-
Type: Bug
-
Resolution: Duplicate
-
Priority: Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
A scope that does not provide a query condition, (e.g. using `without`) defaults to using the default_scope even when unscoped is specified. Test case to reproduce:
class MyClass
include Mongoid::Document
default_scope -> { where(foo: 1) }
scope :no_condition, -> { without(:bar) }
scope :with_condition, -> { where(bar: 1) }
end
> MyClass.unscoped.no_condition #<Mongoid::Criteria selector: {"foo"=>1} options: {:fields=>{"bar"=>0}} class: MyClass embedded: false> > MyClass.unscoped.with_condition #<Mongoid::Criteria selector: {"bar"=>1} options: {} class: MyClass embedded: false>
The with_condition scope correctly removes the default_scope, whereas the no_condition scope keeps the default_scope query.
- duplicates
-
MONGOID-5229 Add Feature Flag: .with_scope should restore previous scope
- Closed
- related to
-
MONGOID-5186 .with_scope should restore previous scope
- Closed