order(*args) public

No documentation

This method has no description. You can help the Ruby on Rails community by adding new notes.

Show source
Register or log in to add new notes.
March 27, 2012
5 thanks


If you want to override previously set order (even through default_scope), use reorder() instead.


User.order('id ASC').reorder('name DESC')

would ignore ordering by id completely

October 28, 2014
1 thank

Ordering on associations

For ordering on the attribute of an associated model you have to include it:

October 30, 2014 - (v3.0.0 - v3.2.13)
1 thank

Order with hash parameters only in ActiveRecord >= 4.0

If you use order with hash parameters on AR3 versions it wont work.

January 12, 2014
0 thanks

using hash as order

order can be specified as a hash, e.g.:

order(id: :desc)

This will prevent “ambiguous column” errors when the order is used with joins or includes.

February 12, 2015
0 thanks


adding to stevo’s comment that reorder is also usefull when you have default scope in your model. eg: default_scope -> { order(created_at: :desc) }