According to the mongoid documentation on Explicit Merging ("Queryable#in - defaults to intersect") I would expect the following query:
Contact.in(id: ['a', 'b']).in(id: ['b', 'c'])
to result in something like this:
=> #<Mongoid::Criteria
selector: {"_id"=>{"$in"=>["b"]}}
options: {}
class: Contact
embedded: false>
But instead I get an overwrite for all imaginable cases:
[1] pry(main)> Contact.in(id: ['a', 'b']).in(id: ['b', 'c'])
=> #<Mongoid::Criteria
selector: {"_id"=>{"$in"=>["b", "c"]}}
options: {}
class: Contact
embedded: false>
[2] pry(main)> Contact.in(id: ['a', 'b']).intersect.in(id: ['b', 'c'])
=> #<Mongoid::Criteria
selector: {"_id"=>{"$in"=>["b", "c"]}}
options: {}
class: Contact
embedded: false>
[3] pry(main)> Contact.in(id: ['a', 'b']).union.in(id: ['b', 'c'])
=> #<Mongoid::Criteria
selector: {"_id"=>{"$in"=>["b", "c"]}}
options: {}
class: Contact
embedded: false>
Am I doing something wrong?
The issue you are facing is caused by Mongoid gem. Upgrading to latest version of Mongoid gem will solve the issue.
More information regarding the bug can be found here
https://github.com/mongoid/origin/pull/83
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With