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

Make unscoped clear current scope or document that it does not

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Unknown
    • Resolution: Fixed
    • None
    • 9.0.0
    • None
    • None
    • Minor Change

    Description

      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>
      

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: