mongoid/mongoid — Issue #1650: to_criteria
Author: semaperepelitsa
Created: 2012-01-27 05:45:30+00:00
State: open

I have a filter object that takes params from request and generate a Mongoid::Criteria on `to_criteria` so that I can merge it into others:

```ruby
Product.published.merge(filter.to_criteria)
```

But I don't like calling to_criteria on each merge so I've monkey-patched Criteria to automatically call to_criteria on merge:

```ruby
class Mongoid::Criteria
# converts the passed object to criteria if it can
def merge_with_proxy(other)
other = other.to_criteria if other.respond_to?(:to_criteria)
merge_without_proxy(other)
end
alias_method_chain :merge, :proxy

def to_criteria
self
end
end
```

Can we have this in the core?