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

Allow primary_key: association option to be composite #51345

Merged

Conversation

nvasilevski
Copy link
Contributor

Fixes: #50850

A bit related to: #49671 (comment)

Association's primary_key can be composite when derived from associated class primary_key or query_constraints. But we don't allow setting it explicitly even though Rails is already capable of supporting it.

This commit allows primary_key association option to be an array.

Here is an example where we already assume that primary_key can be an Array:

if custom_primary_key.is_a?(Array)

Association's `primary_key` can be composite when derived from associated class
`primary_key` or `query_constraints`. But we don't allow setting it explicitly
even though Rails is already capable of supporting it.

This commit allows `primary_key` association option to be an array.
@rafaelfranca rafaelfranca merged commit 2fa7d52 into rails:main Mar 18, 2024
3 of 4 checks passed
@rafaelfranca rafaelfranca deleted the allow-association-primary-key-to-be-an-array branch March 18, 2024 20:32
rafaelfranca added a commit that referenced this pull request Mar 18, 2024
…to-be-an-array

Allow `primary_key:` association option to be composite
@vipulnsward
Copy link
Member

Do such changes need CHANGELOG or considered internal? I see this fixes user facing behaviour?

@nvasilevski
Copy link
Contributor Author

Do such changes need CHANGELOG

Oh, they absolutely do as they are public. Thanks for reminding!

#51410

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.

belongs_to association doesn't work with composite primary_key option
3 participants