I have an array authors=[1,3,7] and I want to get all the posts that match with any or all of these results. something like... posts = Post.find(:all, [:conditions => ''''author_id = ?'', authors]) of course this wont work but I need something like it that works.. thanks -- Posted via http://www.ruby-forum.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 -~----------~----~----~----~------~----~------~--~---
Vapor .. wrote:> I have an array authors=[1,3,7] and I want to get all the posts that > match with any or all of these results. > something like... > > posts = Post.find(:all, [:conditions => ''''author_id = ?'', authors]) > > of course this wont work but I need something like it that works.. > > thanksSimply use posts = Post.find(:all, :conditions => [''author_id IN (?)'', authors]) -- Posted via http://www.ruby-forum.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 -~----------~----~----~----~------~----~------~--~---
> > Vapor .. wrote: >> I have an array authors=[1,3,7] and I want to get all the posts that >> match with any or all of these results. >> something like... >> >> posts = Post.find(:all, [:conditions => ''''author_id = ?'', authors]) >> >> of course this wont work but I need something like it that works..You can also use Post.find(authors), as it accepts an array. That fires off SQL identical to what Wouter posted. Doug On Jan 10, 2008, at 11:41 AM, Wouter de Bie wrote:> > Vapor .. wrote: >> I have an array authors=[1,3,7] and I want to get all the posts that >> match with any or all of these results. >> something like... >> >> posts = Post.find(:all, [:conditions => ''''author_id = ?'', authors]) >> >> of course this wont work but I need something like it that works.. >> >> thanks > > Simply use > > posts = Post.find(:all, :conditions => [''author_id IN (?)'', authors]) > -- > Posted via http://www.ruby-forum.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 -~----------~----~----~----~------~----~------~--~---