Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Chaining 'OR' based scopes results in an 'OR' wrapper instead of 'AND' #499

benzittlau opened this Issue Feb 19, 2013 · 0 comments


None yet
1 participant

If I chain two scopes that use an "OR" operator, instead of the resulting query being a logical 'AND' of those two scopes it's a logical 'OR':

 def self.free
    where({:$or => [{:plans => {:$size => 0}}, {:plans => 'Free'}]})

def self.for_connector(connector)
    where({:$or => [{:'connection_info.conn1' => connector}, {:'connection_info.conn2' => connector}]})

Note the resulting plucky query when these are changed. I would instead expect these two scopes to be wrapped in a higher level 'AND' instead of being combined into one 'OR'.

1.9.3p194 :004 > Transaction.for_connector('Test').free
 => #<Plucky::Query $or: [{:"connection_info.conn1"=>"Test"}, {:"connection_info.conn2"=>"Test"}, {:plans=>{:$size=>0}}, {:plans=>"Free"}], transformer: #<Proc:0x007f82d50f0348@/Users/bzittlau/.rvm/gems/ruby-1.9.3-p194@mover_admin/gems/mongo_mapper-0.11.2/lib/mongo_mapper/plugins/querying.rb:76 (lambda)>>

@cheald cheald added a commit to cheald/plucky that referenced this issue Jul 8, 2013

@cheald cheald Rewrite CriteriaHash#merge to be less gnarly. Add $or merging.
This add collapsing of multiple $ors or $ors + $ands containing $ors into a compound $and statement.

* Closes mongomapper/mongomapper#298
* Closes mongomapper/mongomapper#499
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment