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

Add support for nullifying composite primary key has_one associations #48539

Merged
merged 1 commit into from Jun 21, 2023

Conversation

gmcgibbon
Copy link
Member

Motivation / Background

This Pull Request has been created because has_one CPK associations with dependent: :nullify don't currently work.

Detail

This Pull Request changes the nullification code in ActiveRecord::Associations::HasOneAssociation to iterate through foreign key columns and nullify them if they don't belong to the model's primary keys.

Additional information

I had to add an extra test model to make a scenario where part of a composite primary key shouldn't be nullified. Does it make sense?

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one change. Changes that are unrelated should be opened in separate PRs.
  • Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: [Fix #issue-number]
  • Tests are added or updated if you fix a bug or add a feature.
  • CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included.

@eileencodes
Copy link
Member

The Railties failure will be fixed by a rebase. Can you fix the rubocop failures?

Composite primary key records need to conditionally unset multiple
column attributes from the associated record in order to properly
support dependent: nullify.
@gmcgibbon
Copy link
Member Author

gmcgibbon commented Jun 21, 2023

Done. Looks like we're green now! Thank you

@eileencodes eileencodes merged commit d268124 into rails:main Jun 21, 2023
9 checks passed
@gmcgibbon gmcgibbon deleted the fix_cpk_nullify branch June 21, 2023 20:05
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