This project is archived and is in readonly mode.

#2775 ✓stale
Paul Campbell

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

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>

Attachments

Pages