I was hoping that AR''s find_by_* magic methods would help me retrieve multiple items somewhat like the following: names_to_find = [''Larry'', ''Moe'', ''Curly''] found_people = Person.find_by_name(names_to_find) Is there a way to accomplish this using find_by_* (or even find(:all) using some sort of conditions) or must I resort to SQL (of which I happily know very little). Thanks, Chris -- 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 -~----------~----~----~----~------~----~------~--~---
On Thu, May 22, 2008 at 3:40 PM, Chris Parrish <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > I was hoping that AR''s find_by_* magic methods would help me retrieve > multiple items somewhat like the following: > > names_to_find = [''Larry'', ''Moe'', ''Curly''] > found_people = Person.find_by_name(names_to_find) > > Is there a way to accomplish this using find_by_* (or even find(:all) > using some sort of conditions) or must I resort to SQL (of which I > happily know very little).Use Person.find_all_by_name(names_to_find). :-) Craig --~--~---------~--~----~------------~-------~--~----~ 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 May 22, 8:40 pm, Chris Parrish <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I was hoping that AR''s find_by_* magic methods would help me retrieve > multiple items somewhat like the following: > > names_to_find = [''Larry'', ''Moe'', ''Curly''] > found_people = Person.find_by_name(names_to_find) >find_by_xxx is mapped to a find :first, its counterpart is find_all_by... Were you to write it out in full you''d write Person.find :all, :conditions => ["name in (?)", names] or Person.find :all, :conditions => {:name => names} Fred> Is there a way to accomplish this using find_by_* (or even find(:all) > using some sort of conditions) or must I resort to SQL (of which I > happily know very little). > > Thanks, > Chris > -- > Posted viahttp://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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi everyone i''m new to ROR.
I did try before the method
Person.find :all, :conditions => ["name in (?)", names]
or Person.find :all, :conditions => {:name => names}
but its gave me a error uninitialized constant Person.
It is must implement a method for Person in order to use it.
Thank
Wawa
--
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
-~----------~----~----~----~------~----~------~--~---
Hi Emmie, ----- Original Message ----- Emmie Wawa wrote:> Hi everyone i''m new to ROR.Welcome!> I did try before the method > Person.find :all, :conditions => ["name in (?)", names] > or Person.find :all, :conditions => {:name => names} > but its gave me a error uninitialized constant Person.The error is telling you that Rails can''t find a model named Person.rb. Do you have one? And a table named persons? Bill --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Wouldn''t the table be named "people"? :)
Inflector.pluralize("person") => "people"
On Tue, May 27, 2008 at 12:34 PM, Bill Walton
<bill.walton-xwVYE8SWAR3R7s880joybQ@public.gmane.org>
wrote:
>
> Hi Emmie,
>
> ----- Original Message -----
> Emmie Wawa wrote:
>
> > Hi everyone i''m new to ROR.
>
> Welcome!
>
> > I did try before the method
> > Person.find :all, :conditions => ["name in (?)", names]
> > or Person.find :all, :conditions => {:name => names}
> > but its gave me a error uninitialized constant Person.
>
> The error is telling you that Rails can''t find a model named
Person.rb. Do
> you have one? And a table named persons?
>
> Bill
>
>
> >
>
--
Appreciated my help?
Recommend me on Working With Rails
http://workingwithrails.com/person/11030-ryan-bigg
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Oops! Yes it would :-p Thanks for the catch, Ryan!
Best regards,
Bill
----- Original Message -----
From: Ryan Bigg (Radar)
To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
Sent: Tuesday, May 27, 2008 12:24 AM
Subject: [Rails] Re: Retrieving Mutliple Records using find_by_*
Wouldn''t the table be named "people"? :)
Inflector.pluralize("person") => "people"
On Tue, May 27, 2008 at 12:34 PM, Bill Walton
<bill.walton-xwVYE8SWAR3R7s880joybQ@public.gmane.org> wrote:
Hi Emmie,
----- Original Message -----
Emmie Wawa wrote:
> Hi everyone i''m new to ROR.
Welcome!
> I did try before the method
> Person.find :all, :conditions => ["name in (?)", names]
> or Person.find :all, :conditions => {:name => names}
> but its gave me a error uninitialized constant Person.
The error is telling you that Rails can''t find a model named
Person.rb. Do
you have one? And a table named persons?
Bill
--
Appreciated my help?
Recommend me on Working With Rails
http://workingwithrails.com/person/11030-ryan-bigg
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Hi Bill,
Ok thanks I have solved the error uninitialized constant Person but now
i have another error showing me that i have a nil object when you
didn''t
expect it! (NoMethodError).
The error occurred while evaluating
nil.find :all, :conditions => {:name => names}
Thanks
wawa
--
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
-~----------~----~----~----~------~----~------~--~---
What code are you using to get that error? On Tue, May 27, 2008 at 3:02 PM, Emmie Wawa < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hi Bill, > > Ok thanks I have solved the error uninitialized constant Person but now > i have another error showing me that i have a nil object when you didn''t > expect it! (NoMethodError). > The error occurred while evaluating > nil.find :all, :conditions => {:name => names} > > Thanks > > wawa > -- > Posted via http://www.ruby-forum.com/. > > > >-- Appreciated my help? Recommend me on Working With Rails http://workingwithrails.com/person/11030-ryan-bigg --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi Emmie, Emmie Wawa wrote:> Ok thanks I have solved the error uninitialized constant > Person but now i have another error showing me that i > have a nil object when you didn''t expect it! (NoMethodError). > The error occurred while evaluating > nil.find :all, :conditions => {:name => names}You''ll need to show us some code to help further. How exactly did you solve the unintialized constant error? Best regards, Bill --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---