문제

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.

도움이 되었습니까?

해결책

I think this should work

where{name.in(languages_array)}

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top