Searching for multiple possible values

Hi,
I’m trying to do an search for multiple possible values in one
database field. I have an array and want to find any of the values in
the array in the database and return the results.

So basically
arr = [‘item1’, ‘item2’, ‘item3’]

and I want to Model.find :all, :conditions => {:items => arr}
and find all the entries where :items equals any of the strings in
array.

What is the preferred way to do this?

Thanks,
JB

On Sep 22, 8:17 am, Jables [email protected] wrote:

array.
Assuming :items is the name of a database field, that will do exactly
what you want (ie it will generate "items in (‘item1’, ‘item2’,
‘item3’))

Fred

Thanks

On Mon, Sep 22, 2008 at 9:17 AM, Jables [email protected] wrote:

and find all the entries where :items equals any of the strings in
array.

IN is supposed to be faster than OR. In addition {:items => arr} is
very concise, that’s the recommended solution.

Take into account that if the array is huge the SQL may be too large.
In MySQL for example IN() has no limit in the number of arguments it
may receive, but a single SQL over the wire cannot exceed
max_allowed_packet.