Question

I have the following query in Squeel:

languages = where{ (name == 'English') | 
 (name == 'Spanish')  | 
 (name == 'German')  | 
 (name == 'French')  | 
 ...
}

Which works fine but I was wodering if there was a way to iterate through an array with those values to make it easier to add and remove languages. Say I created and array:

languages_array = %w[ English Spanish French ... ]

Is there any way to iterate with Squeel in a Where block?

I've tried everything I can think of without success.

Thanks.

Was it helpful?

Solution

I think this should work

where{name.in(languages_array)}

OTHER TIPS

You don't need squeel for this type of query: where(name: languages_array) will do what you need - it'll translate to

WHERE name IN ('English', 'Spanish', 'French', ...)

which is probably what you need.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top