All - I have an array of values arr = [''a'',''b'',''c''] and I want to find all records such that :value is contained within the array. Something like: Record.find(:all,:conditions=>{:value=>arr.include?}) Does AR support this, and if so what is the syntax? Thanks, Drew -- 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 -~----------~----~----~----~------~----~------~--~---
Drew Olson wrote:> All - > > I have an array of values arr = [''a'',''b'',''c''] and I want to find all > records such that :value is contained within the array. Something like: > > Record.find(:all,:conditions=>{:value=>arr.include?}) > > Does AR support this, and if so what is the syntax? > > Thanks, > DrewI''m out of office so cant really test but you could probably do something along the lines of: Record.find(:all,:conditions=>{ "value IN (?), arr.join(",") }) -- 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 -~----------~----~----~----~------~----~------~--~---
Ben wrote:> > I''m out of office so cant really test but you could probably do > something along the lines of: > Record.find(:all,:conditions=>{ "value IN (?), arr.join(",") })Thanks for putting me on the right track. It seems I can do: Record.find(:all,:conditions=>["value IN (?)", arr]) -- 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 -~----------~----~----~----~------~----~------~--~---
you can also do Model.find_all_by_value([''a'', ''b'', ''c'']) ex: authors = [''Hemingway'', ''Dickinson'', ''Shakespeare''] Books.find_all_by_author(authors) where ''author'' is a column in the ''books'' table On 2/21/07, Drew Olson <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Ben wrote: > > > > I''m out of office so cant really test but you could probably do > > something along the lines of: > > Record.find(:all,:conditions=>{ "value IN (?), arr.join(",") }) > > Thanks for putting me on the right track. It seems I can do: > > Record.find(:all,:conditions=>["value IN (?)", arr]) > > -- > 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 -~----------~----~----~----~------~----~------~--~---
Chris Hall wrote:> you can also do > > Model.find_all_by_value([''a'', ''b'', ''c''])Wow, much cleaner. Thanks for that! -Drew -- 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 -~----------~----~----~----~------~----~------~--~---
You can simply do Record.find(:all, :conditions => {:value => arr}) Simon Drew Olson wrote:> All - > > I have an array of values arr = [''a'',''b'',''c''] and I want to find all > records such that :value is contained within the array. Something like: > > Record.find(:all,:conditions=>{:value=>arr.include?}) > > Does AR support this, and if so what is the syntax? > > Thanks, > Drew > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Feb 21, 2007, at 16:07 , Drew Olson wrote:> I have an array of values arr = [''a'',''b'',''c''] and I want to find all > records such that :value is contained within the array. Something > like: > > Record.find(:all,:conditions=>{:value=>arr.include?}) > > Does AR support this, and if so what is the syntax?Does :conditions => [''value IN (?)'', arr] do what you need? -- Jakob Skjerning - http://mentalized.net --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---