ActiveRecord find with array is an ordered return
You probably already know that passing an Array
to an ActiveRecord
.find
will do an IN
query and return the results.
User.find([1,2,37])
=> [<User id: 1>, <User id: 2>, <User id: 37>]
But did you know that the order of the array affects the returned result order? This is an order not done at the database level.
User.find([37,2,1])
=> [<User id: 37>, <User id: 2>, <User id: 1>]
Tweet