-
Type: Improvement
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: Query
-
None
Mongoid implements strategies called override, union and intersect. These are available as methods on Criteria. These are presently undocumented (union is given once in an example in the tutorial with no explanation how it works, intersect is not mentioned at all) despite being applied by default (union to #all, intersect to #in and #nin). These strategies alter the way the next condition is added to the criteria, similarly to one of the forms of the #not method. These methods only handle specific forms of adding operators to queries, for example they handle the #in method but not the $in operator:
irb(main):024:0> Band.where(foo:{'$in'=>[3]}).union.where(foo:{'$in'=>[4]}) => #<Mongoid::Criteria selector: {"foo"=>{"$in"=>[]}} options: {} class: Band embedded: false> irb(main):025:0> Band.where(foo:{'$in'=>[3]}).union.in(foo:[4]) => #<Mongoid::Criteria selector: {"foo"=>{"$in"=>[3, 4]}} options: {} class: Band embedded: false>
union on criteria overall does not do anything (or behaves incorrectly depending on point of view):
irb(main):028:0> Band.where(foo:3).union.where(foo:4) => #<Mongoid::Criteria selector: {"foo"=>4} options: {} class: Band embedded: false>
This ticket is to:
Document strategies overall, pointing out that they are only respected by a handful of operators (all/in/nin) and only in some of the ways of using these operators (via query methods)
Change default behavior of operators supporting strategies to use the simple addition, i.e. join with $and to existing conditions
Provide examples in the tutorial of specifying all of the available strategies and illustrating how the strategy changes the generated query
Point out that strategies expand Range on client side
- is duplicated by
-
MONGOID-4807 Make $all combinations in Criteria behave like other logical combinations
- Closed
- related to
-
MONGOID-4697 Implement Arel-style "and", "or" and "not" combination of scopes
- Closed
- links to