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

Fix destroy_all for has_many through: associations that points to a CPK model #48474

Conversation

nvasilevski
Copy link
Contributor

This PR fixes destroy_all behavior for a has_many through: association that points to a model with composite primary key however the association itself uses just id column to build the reference

Since primary_key: :id in association definition means " use the id column as primary/foreign key Rails should avoid accessing values for the column using public_send as it ends up calling the id method which in Rails has special meaning - the identifier or in other words "values behind the primary key columns" which in composite primary key context is not the same as id column. Instead we are using _read_attribute which directly fetches the value of the id column.

@eileencodes eileencodes merged commit 3d27965 into rails:main Jun 14, 2023
9 checks passed
@eileencodes eileencodes deleted the fix-destroy-all-for-through-associations-on-cpk-models branch June 14, 2023 18:36
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