Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 918791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:26:06+00:00 2026-05-15T18:26:06+00:00

I have a ticket model which has a method inside called closes_in that calculates

  • 0

I have a ticket model which has a method inside called closes_in that calculates the time left from the DB field start_date:date to now. Currently my find query is:

    @tickets = Ticket.find(:all, 
                       :origin => @user.coords, 
                       :order => 'distance',

I can’t just put in closes_in as I get an error. How do I make it so I can use closes_in to sort the query if it’s a method and not an actual field in the DB?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T18:26:07+00:00Added an answer on May 15, 2026 at 6:26 pm

    If you are using MySQL:

    @tickets = Ticket.all(:order => "DATEDIFF(CURDATE(), start_date)")
    

    If you are using PostgreSQL:

    @tickets = Ticket.all(:order => "AGE(start_date)")
    

    This way you are using DB for sorting. Sorting using ruby should be restricted to a small data-set that is guaranteed to remain small.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Crystal Report that looks like: Date | Person | Ticket |
I have an access DB which we use to track tickets. Each ticket may
In Django, I've got a Checkout model, which is a ticket for somebody checking
Hi I have a method that returns an array of support tickets. Each support
I have a ticker which items are updated using polling. I have written a
I have a nested function to show/hide paragraphs news-ticker-style. The problem is that when
I have a SharePoint List to which I'm adding new ListItems using the Client
I have a django model roughly as shown below: class Event(db.Model): creator = db.ReferenceProperty(User,
I have two tables with the following columns: table1: id, agent_name, ticket_id, category, date_logged
It's very painful to add multiple tickets to Trac or to have it as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.