1

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)

2 Answers 2

5

I prefer using

Collection.where(:assets.in => [[], my_asset])
Sign up to request clarification or add additional context in comments.

Comments

2

try using any_of

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.