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

Improve cpk validation check #48724

Merged
merged 3 commits into from Jul 12, 2023

Conversation

gmcgibbon
Copy link
Member

Motivation / Background

This Pull Request has been created because the composite primary key validation check is incomplete. It only checks for one side of the association having a CPK. It should actually check both sides so that more edge cases are caught.

Detail

This Pull Request changes the CPK validation check condition to include active_record.composite_primary_key?, which account for CPK owners of associations (not just CPK association classes).

Additional information

This PR also changes a few other things in other commits. It improves the CPK validation check error message, and changes <reflection>.association_primary_key behaviour to better support CPK. The fix for belongs_to assignment included in the #association_primary_key change commit doesn't appear to be released, so I don't think a changelog is needed there.

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.

Catches more bugs in CPK assocaitions by validating the shape of keys on
both ends of the association.

Co-authored-by: Nikita Vasilevsky <nikita.vasilevsky@shopify.com>
gmcgibbon and others added 2 commits July 12, 2023 16:02
Support assignment of belongs_to associations with query constraints.
This improves errors messages for composite key mismatches, and some
edge cases with query constraint lists.

Co-authored-by: Nikita Vasilevsky <nikita.vasilevsky@shopify.com>
A developer may not always want to specify query constraints. If, for
example they would like to use a non-composite primary key in an
asscoaition, they need to use primary_key/foreign_key options instead.

Co-authored-by: Nikita Vasilevsky <nikita.vasilevsky@shopify.com>
@gmcgibbon gmcgibbon force-pushed the improve_cpk_validation_check branch from 28069f6 to ab04511 Compare July 12, 2023 21:03
@eileencodes eileencodes merged commit a8e653f into rails:main Jul 12, 2023
9 checks passed
@gmcgibbon gmcgibbon deleted the improve_cpk_validation_check branch July 12, 2023 22:13
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