문제

I want to make a request which returns elements from my collection if a string is in an array or if the array is empty. I tried the following:

Collection.all_of(or: [{ assets: my_asset }, { assets: [] } ])

But this doesn't work.

This works but not for the empty arrays:

Collection.where(assets: my_asset)
도움이 되었습니까?

해결책

I prefer using

Collection.where(:assets.in => [[], my_asset])

다른 팁

try using any_of

Collection.any_of({ assets: my_asset }, { assets: [] })
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top