-
Type: Improvement
-
Resolution: Fixed
-
Priority: Unknown
-
Affects Version/s: None
-
Component/s: None
-
None
-
Minor Change
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>
- is related to
-
MONGOID-5329 Ability to remove default scope from Criteria
- Backlog
-
MONGOID-5454 Separate default scope from other query conditions
- Backlog
- related to
-
MONGOID-5506 Update 8.x docs to document unscoped behavior changing in 9.0
- Closed
-
MONGOID-5186 .with_scope should restore previous scope
- Closed
-
MONGOID-5229 Add Feature Flag: .with_scope should restore previous scope
- Closed
- links to