Method: ActiveRecord::QueryMethods#reorder
- Defined in:
- lib/active_record/relation/query_methods.rb
#reorder(*args) ⇒ Object
Replaces any existing order defined on the relation with the specified order.
User.order('email DESC').reorder('id ASC') # generated SQL has 'ORDER BY id ASC'
Subsequent calls to order on the same relation will be appended. For example:
User.order('email DESC').reorder('id ASC').order('name ASC')
generates a query with ‘ORDER BY id ASC, name ASC’.
106 107 108 109 110 111 112 113 |
# File 'lib/active_record/relation/query_methods.rb', line 106 def reorder(*args) return self if args.blank? relation = clone relation.reordering_value = true relation.order_values = args.flatten relation end |