Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.x] Do not apply global scopes when incrementing/decrementing an existing model #47629

Conversation

cosmastech
Copy link
Contributor

@cosmastech cosmastech commented Jul 1, 2023

To close #47620 To reproduce, you can follow the set up that @levu42 provided in the original issue.

Previously, a new query was built from Model@newQueryWithoutRelationships(), which applies global scopes. If the client code already has the model, applying global scopes could potentially make the update query not see the row in the DB. To remedy this, we apply Builder@newQueryWithoutScopes().

Note: I'm unsure if Model@newQueryWithoutRelationships() is actually needed when calling increment/decrement when the model doesn't exist. That could possibly be changed to newQueryWithoutScopes() as well. 🤷 I can't really think of a use case where this would ever be called, so if someone can clue me in, would appreciate the knowledge.

@cosmastech cosmastech marked this pull request as draft July 1, 2023 10:19
@cosmastech cosmastech marked this pull request as ready for review July 1, 2023 11:07
@levu42
Copy link
Contributor

levu42 commented Jul 1, 2023

@cosmastech Thank you for fixing this so quickly!

@cosmastech cosmastech changed the title [10.x] Ignore global scopes when incrementing/decrementing an existing model [10.x] Do not apply global scopes when incrementing/decrementing an existing model Jul 1, 2023
@taylorotwell taylorotwell merged commit b8f385b into laravel:10.x Jul 4, 2023
11 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Eloquent: increment() on Model filtered out by default global scope doesn't get persisted into the database
3 participants