February 4th, 2013, 08:15 PM
How can I make the order of Find results match the order of Array input.
I'm performing a find on a Person model. I'm using an array of ids as the input for my Find method. The array represents the ancestry of a particular person and the order of the array is important.
I would like the find result (relation) to be in the same order as the input ancestry array. Unfortunately, the result returned is sorted in the order of the ids (ascending). Is there a way to prevent this behavior and have returned result in the order of the ancestry_array.
There's not an attribute in the model that reflects the Ancestry order so I don't see a direct way to use the order method.
ancestry_array = Array.new
ancestry_array = [23,45,89,12,90,5]
returned order of relation: 5,12,23,45,89,90
desired order of returned relation: 23,45,89,12,90,5