Hi all Not really sure how to put the subject as I know what I want to do, but really not sure how (or if) I can do it. What I really want to do is this ; people.find_by_name(:all, :conditions => {"name = ?", "john", "bob", "mike", "fred","will"} ) or possibly people.find_by_name(:all, :conditions => {"name =?", "john"} ) Ive no idea if this can be done, or if it can, how to do it. Can someone clue me in? Many thanks Jonathan -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
The raw SQL way to say this would be "name IN(''john'',''bob'',''mike'',''fred'',''will'')" but I''m not sure how to say that in the Rails finder format. Walter On Oct 6, 2010, at 3:34 PM, Jonathan Gill wrote:> Hi all > > Not really sure how to put the subject as I know what I want to do, > but really not sure how (or if) I can do it. > > What I really want to do is this ; > > people.find_by_name(:all, :conditions => {"name = ?", "john", "bob", > "mike", "fred","will"} ) > > or possibly > > people.find_by_name(:all, :conditions => {"name =?", "john"} ) > > Ive no idea if this can be done, or if it can, how to do it. > > Can someone clue me in? > > Many thanks > > Jonathan > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Please quote when replying. Walter Davis wrote:> The raw SQL way to say this would be "name > IN(''john'',''bob'',''mike'',''fred'',''will'')" but I''m not sure how to say > that in the Rails finder format. > > Walter:conditions => {:name => [''the'', ''array'', ''goes'', ''here'']} Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks for that Walter. Its getting me a little closer, I''ll dig at it and hope I can get it to play nice. I think find_by_sql is my friend here. Many thanks Jonathan On Oct 6, 8:40 pm, Walter Lee Davis <wa...-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote:> The raw SQL way to say this would be "name > IN(''john'',''bob'',''mike'',''fred'',''will'')" but I''m not sure how to say > that in the Rails finder format. > > Walter > > On Oct 6, 2010, at 3:34 PM, Jonathan Gill wrote: > > > Hi all > > > Not really sure how to put the subject as I know what I want to do, > > but really not sure how (or if) I can do it. > > > What I really want to do is this ; > > > people.find_by_name(:all, :conditions => {"name = ?", "john", "bob", > > "mike", "fred","will"} ) > > > or possibly > > > people.find_by_name(:all, :conditions => {"name =?", "john"} ) > > > Ive no idea if this can be done, or if it can, how to do it. > > > Can someone clue me in? > > > Many thanks > > > Jonathan > > > -- > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > > . > > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en > > .-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
Sorry, I did. Please look at my message in a mail application. Google hides the quote when showing threaded messages. Walter On Oct 6, 2010, at 3:50 PM, Marnen Laibow-Koser wrote:> Please quote when replying. > > Walter Davis wrote: >> The raw SQL way to say this would be "name >> IN(''john'',''bob'',''mike'',''fred'',''will'')" but I''m not sure how to say >> that in the Rails finder format. >> >> Walter > > :conditions => {:name => [''the'', ''array'', ''goes'', ''here'']} > > Best, > -- > Marnen Laibow-Koser > http://www.marnen.org > marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi Marnen> > :conditions => {:name => [''the'', ''array'', ''goes'', ''here'']} >Worked perfectly! Many thanks for that! Cheers Jonathan -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Walter Davis wrote:> Sorry, I did. Please look at my message in a mail application. Google > hides the quote when showing threaded messages.Then please don''t top-post -- quote like this so it''s clear what you''re replying to.> > WalterBest, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Oct 6, 2010, at 3:34 PM, Jonathan Gill wrote:> Hi all > > Not really sure how to put the subject as I know what I want to do, > but really not sure how (or if) I can do it. > > What I really want to do is this ; > > people.find_by_name(:all, :conditions => {"name = ?", "john", "bob", > "mike", "fred","will"} ) > > or possibly > > people.find_by_name(:all, :conditions => {"name =?", "john"} ) > > Ive no idea if this can be done, or if it can, how to do it. > > Can someone clue me in? > > Many thanks > > JonathanIf you want a dynamic finder on name that returns any number of Person records, then you simply want: Person.find_all_by_name([''john'', ''bob'', ''mike'', ''fred'', ''will'']) -Rob Rob Biedenharn Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org http://AgileConsultingLLC.com/ rab-/VpnD74mH8+00s0LW7PaslaTQe2KTcn/@public.gmane.org http://GaslightSoftware.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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Rob Biedenharn wrote:> On Oct 6, 2010, at 3:34 PM, Jonathan Gill wrote: >> or possibly >> >> people.find_by_name(:all, :conditions => {"name =?", "john"} ) >> >> Ive no idea if this can be done, or if it can, how to do it. >> >> Can someone clue me in? >> >> Many thanks >> >> Jonathan > > If you want a dynamic finder on name that returns any number of Person > records, then you simply want: > > Person.find_all_by_name([''john'', ''bob'', ''mike'', ''fred'', ''will''])I wasn''t absolutely sure if the find_by_* syntax would also take an array. Good to know!> > -Rob > > Rob BiedenharnBest, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.