mongoid/mongoid — Issue #1654: Queries via model associations (e.g. #exists?) do not take expected arguments
Author: dznz
Created: 2012-01-30 03:23:11+00:00
State: open

Given the following:

```
class Topic
include Mongoid::Document
embeds_many :submissions
end

class Submission
include Mongoid::Document
embedded_in :topic
field :name, type: String
end

topic = Topic.create()
topic.submissions.create(name: "Foo")
```
Then `topic.submissions.exists?(conditions: {name: "Foo"} )` should return true.

Instead I get an error: `TypeError: can't convert Hash into Integer`.

It appears that Mongoid::Relations::Targets::Enumerable wraps the Mongoid::Criterion::Inclusion methods but uses different method signatures. Affected methods include: `exists?`, `first`, and `last`, though this isn't a comprehensive list.

I haven't offered a patch because I do not understand the proxy/wrapper setup of Mongoid. I consider this a bug rather than a feature because I believe one would expect queries through associations to behave the same as direct collection queries.

Thanks heaps for the Mongoid library and apologies if I've misunderstood something.