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

Make unscoped clear current scope or document that it does not

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 9.0.0
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None
    • Minor Change

      Currently, unscoped does not clear the "current scope" which is what with_scope sets:

      Band.with_scope(Band.foo) do
        Band.unscoped do
          # Band.foo scope still in effect here
        end
      end
      

      This should either be explicitly documented or changed so that unscoped clears the current scope.

      Note that unscoped is documented to clear the default scope which does align with the above shown behavior, however looking at the code above and going by method names I personally would have expected no scope in the innermost block.

      The following example shows that unscoped removes current conditions, leading credence to the idea that unscoped should also remove a scope added by with_scope:

      irb(main):005:0> Band.where(test: 1)
      => 
      #<Mongoid::Criteria
        selector: {"likes"=>2, "test"=>1}
        options:  {}
        class:    Band
        embedded: false>
      
      irb(main):006:0> Band.where(test: 1).unscoped
      => 
      #<Mongoid::Criteria
        selector: {}
        options:  {}
        class:    Band
        embedded: false>
      

            Assignee:
            neil.shweky@mongodb.com Neil Shweky (Inactive)
            Reporter:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: