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

Document that or/nor conditions make default scope one of the disjunction branches

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 7.4.0
    • Affects Version/s: None
    • Component/s: Query
    • Fully Compatible

      If I define a default scope and then use Model.or, the default scope becomes one of the disjunction branches instead of being a top-level condition in addition to whatever was given in the or:

      class Band
        include Mongoid::Document
      
        default_scope -> { where(likes: 2) }
      end
      
      irb(main):001:0> Band.or(likes:3)
      => 
      #<Mongoid::Criteria
        selector: {"$or"=>[{"likes"=>2}, {"likes"=>3}]}
        options:  {}
        class:    Band
        embedded: false>
      

      This also affects nor the same way.

      When this ticket is worked on, "current scope" set with with_scope should be tested in addition to the defaut scope, as well as clearing scopes with unscoped.

            Assignee:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Reporter:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: