Find by array of ids in the same order?

Hi,

I am trying to perform:

@people = Person.find(10,14,5,1)

The RUBY is acting intelligent in fetching the rows, it is sorting my array and fetching the corresponding rows: Essentially I am returned with rows 1,5,10 and 14 in that order..

It is essential for me to retain the order, can I force this happen?

Regards, Sandeep G

Realized it is MYSQL that is acting intelligent in sorting the array, can i force this not to happen?

Sandeep Gudibanda wrote:

Realized it is MYSQL that is acting intelligent in sorting the array, can i force this not to happen?

ids = [10,14,5,1] @people = Person.find ids, :order => "field(id,#{ids.join(',')})"

http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_field