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

.with_scope should restore previous scope

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 7.4.0
    • Affects Version/s: None
    • Component/s: Query
    • None
    • Minor Change

      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
       
      

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

              Created:
              Updated:
              Resolved: