Alex Rivera | Logout

ActiveRecord.find(array_of_ids), preserving order

Asked 2009-11-05T13:34:45.467
107

When you do Something.find(array_of_ids) in Rails, the order of the resulting array does not depend on the order of array_of_ids.

Is there any way to do the find and preserve the order?

ATM I manually sort the records based on order of IDs, but that is kind of lame.

UPD: if it's possible to specify the order using the :order param and some kind of SQL clause, then how?

Edit
Report

1 Answer

-4

There is an order clause in find (:order=>'...') which does this when fetching records. You can get help from here also.

link text

answered 2009-11-05T13:48:03.363

Your Answer