Reputation: 474
This is probably better explained with an example. I have a documents
table that has a country
attribute, for example Document.first.country
could return 'DE'
. I have an array of country codes, for called eu_countries
with the value ["AT", "BE", "BG", "CY", "CZ", "DE"...]
and I would like to query the db and return only documents that have a country code that is in the array.
Something with the same functionality as: Documents.where(country == "AT" or "BE" or "BG" or "CY" or "CZ" or "DE"...)
Upvotes: 0
Views: 138
Reputation: 51191
It's quite simple
Document.where(country: eu_countries)
It is transferred to SQL similar to this:
select documents.* from documents where documents.country IN (values)
Upvotes: 1