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

Fix inspect with non-primary key id attribute #34384

Merged

Conversation

eugeneius
Copy link
Member

Fixes #34380.

The read_attribute method always returns the primary key when asked to read the id attribute, even if the primary key isn't named id, and even if another attribute named id exists.

For the inspect, attribute_for_inspect and pretty_print methods, this behaviour is undesirable, as they're used to examine the internal state of the record. By using _read_attribute instead, we'll get the real value of the id attribute.

@rails-bot
Copy link

r? @schneems

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

The `read_attribute` method always returns the primary key when asked to
read the `id` attribute, even if the primary key isn't named `id`, and
even if another attribute named `id` exists.

For the `inspect`, `attribute_for_inspect` and `pretty_print` methods,
this behaviour is undesirable, as they're used to examine the internal
state of the record. By using `_read_attribute` instead, we'll get the
real value of the `id` attribute.
@eugeneius eugeneius force-pushed the inspect_with_non_primary_key_id_attribute branch from 6a4a643 to 65cd0fd Compare November 6, 2018 01:53
@kamipo kamipo merged commit 212c28a into rails:master Nov 6, 2018
kamipo added a commit to kamipo/rails that referenced this pull request Jun 14, 2020
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

4 participants