-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
I have a bizzarre case of scope chaining...
I have 2 scopes on model
:
scope :xxx, any_of({ :aaa.gt => 0 }, { :bbb.gt => 0 })
scope :yyy, -> { any_of({:ccc => nil}, {:ccc.gt => Time.now}) } # notice the evaluation time
1. When I do
MyModel.xxx
, I get this correct criteria:
=> #<Mongoid::Criteria
selector: {"$or"=>[{:aaa=>{"$gt"=>0.0}}, {:bbb=>{"$gt"=>0.0}}]},
options: {},
class: MyModel,
embedded: false>
2. When I do
MyModel.yyy
, I get another correct criteria:
=> #<Mongoid::Criteria
selector: {"$or"=>[{:ccc=>nil}, {:ccc=>{"$gt"=>2012-07-05 01:58:54 UTC}}]},
options: {},
class: MyModel,
embedded: false>
3. However, strange things start to happen when I chain them together.
MyModel.xxx.yyy
results in
{"$or"=>[{:aaa=>{"$gt"=>0.0}}, {:bbb=>{"$gt"=>0.0}}, {:ccc=>nil}, {:ccc=>{"$gt"=>2012-07-05 02:21:53 UTC}}]}
- ie, instead of doing an
AND(OR,OR)
, I get an
OR
of everything. Wait, but there is more...
MyModel.yyy.xxx
results in
{"$or"=>[{:aaa=>{"$gt"=>0.0}}, {:bbb=>{"$gt"=>0.0}}]}
- wherein the
yyy
scope gets ignored altogether Am I missing something or the chaining of
any_of{{`}} is broken?