Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

ActiveRecord::Base#find ... let :order param accept a Hash or an Array

#2775

I've been using the :order param on finders quite a lot recently, and what with being able to specify a :conditions => {} hash, I've really felt that :order should be as well endowed.

I took a look at a request here: http://www.ruby-forum.com/topic/122335 which was shot down because hashes aren't sorted ... but it was never raised that :order could take an array.

This patch allows you to pass a hash to :order for sorting by one column only in a particular direction, eg:

Developer.find(:all, :order => {:name => :desc})

In addition, if you want to specify multiple sort columns, you can do so by passing in an array of hashes, strings, or symbols:

Developer.find(:all, :order => [{:salary => :asc}, :name, 'id'])

Paul

Reported by Paul Campbell · June 7th, 2009 @ 10:48 AM

State: stale
Milestone: 3.x
Assigned to: nobody
Importance: none

Activity

  1. Paul Campbell
    Paul Campbell
    • Tag set to :order, activerecord

    June 7th, 2009 @ 10:49 AM

  2. Yaroslav Markin
    Yaroslav Markin
    • Tag changed from :order, activerecord to :order, activerecord, patch

    August 14th, 2009 @ 10:14 PM

  3. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.x to 3.x

    May 4th, 2010 @ 06:48 PM

  4. Rohit Arondekar
    Rohit Arondekar
    • State changed from new to stale
    • Importance changed from to

    Marking ticket as stale. If this is still an issue please leave a comment with suggested changes, creating a patch with tests, rebasing an existing patch or just confirming the issue on a latest release or master/branches.

    October 9th, 2010 @ 04:05 AM