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

.with_scope should restore previous scope

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor - P4
    • Resolution: Fixed
    • None
    • 7.4.0
    • Query
    • None
    • Minor Change

    Description

      It's nice to restore previous scope in `.with_scope`, don't you think?

      diff --git a/lib/mongoid/scopable.rb b/lib/mongoid/scopable.rb
      index 76887e78a..7b4f55331 100644
      --- a/lib/mongoid/scopable.rb
      +++ b/lib/mongoid/scopable.rb
      @@ -226,11 +226,12 @@ module Mongoid
             #
             # @since 1.0.0
             def with_scope(criteria)
      +        previous = Threaded.current_scope(self)
               Threaded.set_current_scope(criteria, self)
               begin
                 yield criteria
               ensure
      -          Threaded.set_current_scope(nil, self)
      +          Threaded.set_current_scope(previous, self)
               end
             end
       
      

      Attachments

        Issue Links

          Activity

            People

              oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
              pinarello.marvel@gmail.com 英雄 中野
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: