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

Don't map id to primary key in raw_write_attribute #29464

Merged
merged 1 commit into from Jun 15, 2017

Conversation

@eugeneius
Copy link
Member

@eugeneius eugeneius commented Jun 15, 2017

The raw_write_attribute method is used to update a record's attributes to reflect the new state of the database in update_columns. The hash provided to update_columns is turned into an UPDATE query directly, which means passing an id key results in an update to the id column, even if the model uses a different attribute as its primary key. When updating the record, we don't want to apply the id column change to the primary key attribute, since that's not what happened in the query.

Without the code to handle this case, write_attribute_with_type_cast no longer contains any logic shared between raw_write_attribute and write_attribute, so we can inline the code into those two methods.

The `raw_write_attribute` method is used to update a record's attributes
to reflect the new state of the database in `update_columns`. The hash
provided to `update_columns` is turned into an UPDATE query directly,
which means passing an `id` key results in an update to the `id` column,
even if the model uses a different attribute as its primary key. When
updating the record, we don't want to apply the `id` column change to
the primary key attribute, since that's not what happened in the query.

Without the code to handle this case, `write_attribute_with_type_cast`
no longer contains any logic shared between `raw_write_attribute` and
`write_attribute`, so we can inline the code into those two methods.
@rails-bot
Copy link

@rails-bot rails-bot commented Jun 15, 2017

r? @kaspth

(@rails-bot has picked a reviewer for you, use r? to override)

@eugeneius eugeneius force-pushed the eugeneius:raw_write_attribute branch Jun 15, 2017
@eugeneius eugeneius force-pushed the eugeneius:raw_write_attribute branch 2 times, most recently to 2e4fe3a Jun 15, 2017
@rafaelfranca rafaelfranca merged commit 703128d into rails:master Jun 15, 2017
2 checks passed
2 checks passed
codeclimate no new or fixed issues
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
rafaelfranca added a commit that referenced this pull request Jun 15, 2017
Don't map id to primary key in raw_write_attribute
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants