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 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,

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

Hi Marnen

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

Worked perfectly! Many thanks for that!

Cheers

Jonathan

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.

Walter

Best,

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 Biedenharn Rob@AgileConsultingLLC.com http://AgileConsultingLLC.com/ rab@GaslightSoftware.com http://GaslightSoftware.com/

Rob Biedenharn 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 Biedenharn

Best,