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.
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.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.