You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a Model class has a default global scope, that filters out some records when retrieving them, but you still retrieve them through withoutGlobalScope(ScopeName::class), it's not always possible to use ->increment() on this model instance.
The change to the column that should be incremented is saved in the model's attributes, but isn't persisted into the database. Most likely from my debugging (without understanding Eloquent internals) it looks like the query to update the column in the database applies default global scopes, so it can't find the row to update in the database.
Attached is a repo with a test failing at exactly that point.
What I found out while debugging: This doesn't apply to all global scopes. When the global scope only applies a simple ->where('remaining_times', '>', 0), not the complex (where remaining_times IS NULL or remaining_times > 0), it seems to work fine. I don't know why that is.
Laravel Version
10.4.1
PHP Version
8.2.7
Database Driver & Version
MySQL & SQLite, both broken
Description
When a Model class has a default global scope, that filters out some records when retrieving them, but you still retrieve them through
withoutGlobalScope(ScopeName::class)
, it's not always possible to use->increment()
on this model instance.The change to the column that should be incremented is saved in the model's attributes, but isn't persisted into the database. Most likely from my debugging (without understanding Eloquent internals) it looks like the query to update the column in the database applies default global scopes, so it can't find the row to update in the database.
Attached is a repo with a test failing at exactly that point.
What I found out while debugging: This doesn't apply to all global scopes. When the global scope only applies a simple
->where('remaining_times', '>', 0)
, not the complex(where remaining_times IS NULL or remaining_times > 0)
, it seems to work fine. I don't know why that is.Steps To Reproduce
See failing test in levu42/increment-global-scope-bug@7b514be
The text was updated successfully, but these errors were encountered: