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

  • SEARCH
  • Home
  • 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 171781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T13:02:56+00:00 2026-05-11T13:02:56+00:00

I seem to be unable to use the ActiveRecord::Base.find option :order for more than

  • 0

I seem to be unable to use the ActiveRecord::Base.find option :order for more than one column at a time.

For example, I have a ‘Show’ model with date and attending columns.

If I run the following code:

@shows = Show.find(:all, :order => 'date') 

I get the following results:

[#<Show id: 7, date: '2009-04-18', attending: 2>,   #<Show id: 1, date: '2009-04-18', attending: 78>,   #<Show id: 2, date: '2009-04-19', attending: 91>,   #<Show id: 3, date: '2009-04-20', attending: 16>,  #<Show id: 4, date: '2009-04-21', attending: 136>] 

If I run the following code:

@shows = Show.find(:all, :order => 'attending DESC')  [#<Show id: 4, date: '2009-04-21', attending: 136>,  #<Show id: 2, date: '2009-04-19', attending: 91>,  #<Show id: 1, date: '2009-04-18', attending: 78>,  #<Show id: 3, date: '2009-04-20', attending: 16>,  #<Show id: 7, date: '2009-04-18', attending: 2>] 

But, if I run:

@shows = Show.find(:all, :order => 'date, attending DESC') 

OR

@shows = Show.find(:all, :order => 'date, attending ASC') 

OR

@shows = Show.find(:all, :order => 'date ASC, attending DESC') 

I get the same results as only sorting by date:

 [#<Show id: 7, date: '2009-04-18', attending: 2>,   #<Show id: 1, date: '2009-04-18', attending: 78>,   #<Show id: 2, date: '2009-04-19', attending: 91>,   #<Show id: 3, date: '2009-04-20', attending: 16>,  #<Show id: 4, date: '2009-04-21', attending: 136>] 

Where as, I want to get these results:

[#<Show id: 1, date: '2009-04-18', attending: 78>, #<Show id: 7, date: '2009-04-18', attending: 2>,   #<Show id: 2, date: '2009-04-19', attending: 91>,   #<Show id: 3, date: '2009-04-20', attending: 16>,  #<Show id: 4, date: '2009-04-21', attending: 136>] 

This is the query being generated from the logs:

[4;35;1mUser Load (0.6ms)[0m   [0mSELECT * FROM 'users' WHERE ('users'.'id' = 1) LIMIT 1[0m [4;36;1mShow Load (3.0ms)[0m   [0;1mSELECT * FROM 'shows' ORDER BY date ASC, attending DESC[0m [4;35;1mUser Load (0.6ms)[0m   [0mSELECT * FROM 'users' WHERE ('users'.'id' = 1) [0m 

Finally, here is my model:

  create_table 'shows', :force => true do |t|     t.string   'headliner'     t.string   'openers'     t.string   'venue'     t.date     'date'     t.text     'description'     t.datetime 'created_at'     t.datetime 'updated_at'     t.decimal  'price'     t.time     'showtime'     t.integer  'attending',   :default => 0     t.string   'time'   end 

What am I missing? What am I doing wrong?

UPDATE: Thanks for all your help, but it seems that all of you were stumped as much as I was. What solved the problem was actually switching databases. I switched from the default sqlite3 to mysql.

  • 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. 2026-05-11T13:02:56+00:00Added an answer on May 11, 2026 at 1:02 pm

    I notice that in your first example, the simple :order => ‘date’, record 7 is sorted before record 1. This order is also how you see the results in the multi-column sort, regardless of whether you sort by attending.

    This would seem to make sense to me if the dates weren’t exactly the same, and the date for 7 is before the date for 1. Instead of finding that the dates are exactly equal then proceeding to sort by attending, the query finds that the dates are not equal and simply sorts by that like all the other records.

    I see from browsing around that SQLite doesn’t have a native understanding of DATE or DATETIME data types and instead gives users the choice of floating point numbers or text that they must parse themselves. Is it possible that the literal representation of the dates in the database are not exactly equal? Most people seem to need to use date functions so that dates behave like you would expect. Perhaps there’s a way to wrap your order by column with a date function that will give you something concrete to compare, like date(date) ASC, attending DESC. I’m not sure that syntax works, but it’s an area to look at for solving your problem. Hope that helps.

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

Sidebar

Related Questions

Does anyone have experience with Sparse ? I seem unable to find any documentation,
I seem to be unable to use a base class as a function parameter,
Excuse me if my question may seem inappropriate but i was unable to find
I seem to be unable to use php to securely bind to Active Directory.
For some reason I seem unable to use JSON.stringify on a DOMWindow object. For
I seem to be unable to use x:out to traverse parsed XML. I'm looking
I seem to have a 32bit vs. 64bit problem here. It should be simple
I seem to remember an option in prior versions of pgAdmin where I could
Why does this JSTL expression not seem to be able to use the length
I just found myself a little bit surprised being unable to simply use a

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.