This project is archived and is in readonly mode.
ActiveRecord::Base#find ... let :order param accept a Hash or an Array
Reported by Paul Campbell | June 7th, 2009 @ 10:48 AM | in 3.x
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
Comments and changes to this ticket
-
Paul Campbell June 7th, 2009 @ 10:49 AM
- Tag set to :order, activerecord
-
Yaroslav Markin August 14th, 2009 @ 10:14 PM
- Tag changed from :order, activerecord to :order, activerecord, patch
-
Rohit Arondekar October 9th, 2010 @ 04:05 AM
- 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.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>