-
Type: New Feature
-
Resolution: Unresolved
-
Priority: Unknown
-
None
-
Affects Version/s: None
-
Component/s: Query
I am upgrading from Mongoid 6.4.8 to 7.4.0. Many changes I have been able to work through, but one persists and is causing a few issues.
How do I replace a where condition created with the `ne` method? I have a model, User. It has a default scope that, among other conditions, only selects users where they that are not preview users and have accepted their invite (datetime field invite_accepted_at).
default_scope -> { where(is_preview_user: false, blocked: false).ne(invite_accepted_at: nil) }
In some places, I need to get all users, including those who haven't accepted the invite.
User.where(invite_accepted_at: nil).count
In 6.4.8, this produced a query that looked like this:
```
{"is_preview_user"=>false, "blocked"=>false, "invite_accepted_at"=>nil }```
However, in 7.4.0, this produces a query that looks like this:
```
{"is_preview_user"=>false, "blocked"=>false, "invite_accepted_at"=>
, "$and"=>[
{"invite_accepted_at"=>nil}]}
```
As you can see, the 7.4.0 is trying to get users where invite_accepted_at is both nil and not nil, resulting in no users returned.
So is there a method I can call, a change I can make, or a setting I can enable to generate the right query, namely, the later call to invite_accepted_at replaces the earlier one.
I tried:
User.override.where(invite_accepted_at: nil)
but it seems to have no effect.
Would appreciate being pointed in the right direction.
- is related to
-
MONGOID-5330 Operator methods overwrite previous conditions
- Closed
- related to
-
MONGOID-4689 Mongoid::Criteria#find searches globally, does not restrict to criteria
- Closed
-
MONGOID-5214 Make unscoped clear current scope or document that it does not
- Closed