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

Avoid scoping update transaction when calling update! on a relation #43192

Merged
merged 1 commit into from
Sep 9, 2021

Conversation

dylanahsmith
Copy link
Contributor

Problem

#33470 reported unexpected scoping when calling ActiveRecord::Relation#update which not only applied the relation's scope to the query for the records to update, but the scope also affected the Active Record callbacks that get triggered from the update. Unfortunately, the fix for that was done just for update and not also for update!.

Solution

The fix for #33470 was to define ActiveRecord::Relation#update to avoid method_missing being called on the relation, which is where the scoping was being applied. Similarly, this PR defines ActiveRecord::Relation#update! which makes these methods consistent in how scoping is applied again.

This makes scoping consistent with ActiveRecord::Relation#update.
ActiveRecord::Relation#update was defined specifically to avoid this
unexpected scoping in Active Record callbacks triggered from the update
which otherwise get introduced by ActiveRecord::Relation#method_missing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants