Find_by_id with multiple ids?

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

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

Please quote when replying.

Walter D. 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
[email protected]

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

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:34 PM, Jonathan G. 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’])

-Rob

Rob B.
[email protected] http://AgileConsultingLLC.com/
[email protected] http://GaslightSoftware.com/

Walter D. 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.

Walter

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

Hi Marnen

:conditions => {:name => [‘the’, ‘array’, ‘goes’, ‘here’]}

Worked perfectly! Many thanks for that!

Cheers

Jonathan

Rob B. wrote:

On Oct 6, 2010, at 3:34 PM, Jonathan G. 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 B.

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs