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

AR 6.1: Fix update_all to update loaded associations #620

Merged
merged 1 commit into from
Dec 19, 2024

Conversation

glizda
Copy link
Contributor

@glizda glizda commented Dec 18, 2024

Addresses #619

Overview

In ActiveRecord 6.1, calling update_all on association (ex. user.readings.update_all(rating: 3)) not only updates the records in the DB, but also updates the loaded association objects. In other words, when you then use user.readings, they will have updated rating values.

When composite_primary_key gem is used, this behaviour is different, even for models without composite primary key defined (because update_all in ActiveRecord::Relation is overwritten for all AR models).

This PR fixes it. I changed the update_all and delete_all methods to more closely resemble those from Rails 6.1 source (with the important difference of how where constraints are built for composite primary key models).

@cfis
Copy link
Contributor

cfis commented Dec 19, 2024

Cool - thanks!

@cfis cfis merged commit 4741ef0 into composite-primary-keys:ar_6.1.x Dec 19, 2024
18 of 20 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.

2 participants