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?
id
—_id
or any random field name, it works properly. Using_id
in your case may be a way to go, but it still looks like a bug._id
but with field aliases as well. I think I know how to fix that in Origin._id
. Should I open an issue for the Origin project on github? Or since you know how to fix it, do you open a pull-request? Would be great!