Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-5454

Separate default scope from other query conditions

    • Type: Icon: New Feature New Feature
    • Resolution: Unresolved
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: Query

      As described in https://jira.mongodb.org/browse/MONGOID-5454?focusedCommentId=4731472&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-4731472, AR tracks the default scope separately from other query conditions. We should investigate having the same behavior in Mongoid.

      Of particular interest is interaction with https://jira.mongodb.org/browse/MONGOID-5214.


      Original report:

      Please note the following. The .nor method merges in the default scope and effectively negates it (i.e. flips its meaning). I think this is completely unexpected by users.

       

      class Band
        include Mongoid::Document
      
        default_scope ->{ where(foo: 1) }
      end
      
      Band.all
      #=> <Mongoid::Criteria selector: {"foo"=>1} ...
      
      Band.nor([{name: "Tool" }])
      #=> <Mongoid::Criteria selector: {"$nor"=>[{"foo"=>1}, {"name"=>"Tool"}]}
      
      # EXPECTED:
      #=> <Mongoid::Criteria selector: {"foo"=>1, "$nor"=>[{"name"=>"Tool"}]}
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            shields@tablecheck.com Johnny Shields
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: