Domain Name Forum  

Go Back   Domain Name Forum > Web Design & Development > Website Development
Register FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 02-04-2013, 09:37 PM
Jack Hard Jack Hard is offline
Junior Member
 
Join Date: Dec 2012
Posts: 11
Default 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. 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
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 10:58 PM.

| Webmaster Forum | | Domain Name Forum |



Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.