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
On Thu, May 22, 2008 at 3:40 PM, Chris P.
[email protected] 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
On May 22, 8:40 pm, Chris P. [email protected]
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
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
Wouldn’t the table be named “people”?
Inflector.pluralize(“person”) => “people”
On Tue, May 27, 2008 at 12:34 PM, Bill W. [email protected]
wrote:
I did try before the method
–
Appreciated my help?
Recommend me on Working With Rails
http://workingwithrails.com/person/11030-ryan-bigg
Hi Emmie,
----- Original Message -----
Emmie W. 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
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
Oops! Yes it would :-p Thanks for the catch, Ryan!
Best regards,
Bill
----- Original Message -----
From: Ryan B. (Radar)
To: [email protected]
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 W.
[email protected] wrote:
Hi Emmie,
----- Original Message -----
Emmie W. 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
Hi Emmie,
Emmie W. 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
What code are you using to get that error?
On Tue, May 27, 2008 at 3:02 PM, Emmie W. <
[email protected]> wrote:
wawa
Posted via http://www.ruby-forum.com/.
–
Appreciated my help?
Recommend me on Working With Rails
http://workingwithrails.com/person/11030-ryan-bigg