|
#1
|
|||
|
|||
How can I make the order of Find results match the order of Array input
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. I hoping to achieve this with ruby on rails if possible. ancestry_array = Array.new ancestry_array = [23,45,89,12,90,5] Person.find(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 |
|
|