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
- is cloned by
-
MONGOID-5229 Add Feature Flag: .with_scope should restore previous scope
- Closed
- is related to
-
MONGOID-5586 unscoped has no effect when a scope does not provide a query condition
- Closed
-
MONGOID-5215 Document that or/nor conditions make default scope one of the disjunction branches
- Closed
-
MONGOID-5214 Make unscoped clear current scope or document that it does not
- Closed
- links to