Using Arel in ActiveRecord ORDER Queries
I utilize Arel in ActiveRecord where
all the time but it never occured to me that order
can also take an Arel node.
Procedure.order(Procedure.arel_table[:name].desc)
=> SELECT "procedures".* FROM "procedures" ORDER BY "procedures"."name" DESC
For such a trivial example I'd say that it's much clearer to just use ActiveRecord in this case.
Procedure.order(name: :desc)
=> SELECT "procedures".* FROM "procedures" ORDER BY "procedures"."name" DESC
Cool piece of knowledge for possible use in a more complex ordering case.
Tweet