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

Use _read_attribute when autosaving has_one associations #48489

Merged
merged 1 commit into from
Jun 16, 2023

Conversation

gmcgibbon
Copy link
Member

@gmcgibbon gmcgibbon commented Jun 15, 2023

Motivation / Background

This Pull Request has been created because composite primary key models do not autosave properly when their association primary key is set to :id. In models with composite primary keys, the #id accessor will return an array, where we actually want the id column value.

Detail

This Pull Request changes has_one autosaving to use _read_attribute instead of public_send so that it won't use the #id accessor.

Additional information

Are we concerned with this breaking behaviour of existing apps?

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

I'm not sure if the test failures are related to this or from another PR that went in today. Can you take a look at the failures?

@gmcgibbon
Copy link
Member Author

Oh yeah, I remember this, some DBs don't like nil PKs. Will fix, thanks

In models with composite primary keys, the #id accessor will return an
array, where we actually want the id column value.
@gmcgibbon gmcgibbon force-pushed the _read_attribute_has_one_autosave branch from 79147d6 to 4d04775 Compare June 15, 2023 20:52
@eileencodes eileencodes merged commit 2f833a6 into rails:main Jun 16, 2023
9 checks passed
@gmcgibbon gmcgibbon deleted the _read_attribute_has_one_autosave branch June 19, 2023 18:34
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