rails/rails — pull request #10891 by oelmekki (2013-06-08 16:42:34+00:00)
Title: Add `#any_of` query method to active_record

This method is inspired by [any_of from mongoid](http://two.mongoid.org/docs/querying/criteria.html#any_of).

It allows to compute an `OR` link query that leverages AR's `#where` syntax:

```ruby
manual_removal = User.where(id: params[:users][:destroy_ids])
users = User.any_of(manual_removal, "email like '%@example.com'", {banned: true}).destroy_all
```

It can be used directly on model class, or through an association, or
behind an other relation.

```ruby
manual_removal = User.where(id: params[:users][:destroy_ids])
User.any_of(manual_removal, "email like '%@example.com'", {banned: true})
@company.users.any_of(manual_removal, "email like '%@example.com'", {banned: true})
User.where(offline: false).any_of( manual_removal, "email like '%@example.com'", {banned: true})
```

Its main purpose is to both :

* remove the need to write a sql string when we want an `OR`
* allows to write dynamic `OR` queries, which would be a pain with a string