0

This is a question that spun out of "Rails, how do I chain scopes with an "and" operator between them?".

In the accepted answer, the code example generates SQL looking something like:

"where 'age' similar to '%(foo|bar)%' AND 'name' similar to '%(foo|bar)%' AND

... and so on.

How would I implement this if I want to chain the scopes with OR instead of AND?

Community
  • 1
  • 1
Majoren
  • 983
  • 5
  • 16
  • 36

1 Answers1

3

check the any_of gem.

Lets you do things like:

banned_users      = User.where(banned: true)
unconfirmed_users = User.where("confirmed_at IS NULL")
inactive_users    = User.where.any_of(banned_users, unconfirmed_users)
apneadiving
  • 114,565
  • 26
  • 219
  • 213