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

Add Feature Flag: .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
    • Fully Compatible

      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:
            neil.shweky@mongodb.com Neil Shweky (Inactive)
            Reporter:
            pinarello.marvel@gmail.com 英雄 中野
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: