ActiveRecord where field = ? array of possible values
From here it appears to be done using an SQL in
statement:
Model.where('id IN (?)', [array of values])
Or more simply, as kdeisz pointed out (Using Arel to create the SQL query):
Model.where(id: [array of values])
From the ActiveRecord Query Interface guide
If you want to find records using the IN expression you can pass an array to the conditions hash:
Client.where(orders_count: [1,3,5])
For readability, this can be simplified even further, to:
Model.find_by(id: [array of values])
This is equivalent to using where
, but more explicit:
Model.where(id: [array of values])