How can i make ActiveRecord find in order for an array parameter? Ex. for Test.find([1, 2, 3, 4, 5]) it should return test.id=1 as the first entry. Right, it just returns in a random order. thanks --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
You''ll need to use the :order option. Test.find([1,2,3,4,5], :order => "id") -Dan Manges http://www.dcmanges.com/blog On Sep 22, 4:24 pm, wheels <wheels...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> How can i make ActiveRecord find in order for an array parameter? > > Ex. for Test.find([1, 2, 3, 4, 5]) > it should return test.id=1 as the first entry. > > Right, it just returns in a random order. > > thanks--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Assuming that you''re trying to order them by the id, you can sort the array when you pass it into .find. Test.find( array_name.sort ) Good luck! Cheers, Robby On Mon, Sep 22, 2008 at 10:19 PM, Dan Manges <daniel.manges-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > You''ll need to use the :order option. > Test.find([1,2,3,4,5], :order => "id") > > -Dan Manges > http://www.dcmanges.com/blog > > On Sep 22, 4:24 pm, wheels <wheels...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> How can i make ActiveRecord find in order for an array parameter? >> >> Ex. for Test.find([1, 2, 3, 4, 5]) >> it should return test.id=1 as the first entry. >> >> Right, it just returns in a random order. >> >> thanks > > >-- Robby Russell Chief Evangelist, Partner PLANET ARGON, LLC design // development // hosting http://www.planetargon.com/ http://www.robbyonrails.com/ aim: planetargon +1 503 445 2457 +1 877 55 ARGON [toll free] +1 815 642 4068 [fax] --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Mark Reginald James
2008-Sep-23 06:02 UTC
Re: ActiveRecord find in order for an array parameter
wheels wrote:> How can i make ActiveRecord find in order for an array parameter?http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/158dc2d879b2fb1 -- Rails Wheels - Find Plugins, List & Sell Plugins - http://railswheels.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---