aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/core.rb
diff options
context:
space:
mode:
authorEugene Kenny <elkenny@gmail.com>2018-11-06 01:51:52 +0000
committerEugene Kenny <elkenny@gmail.com>2018-11-06 01:51:52 +0000
commit65cd0fda2572ac9c78d8582496a9009d0c48df08 (patch)
treea1775a4f7690423034d60e4168501efc45d268f4 /activerecord/lib/active_record/core.rb
parenta8c06c2d7dfa49a9fede1eec65c1058fe0fac82b (diff)
downloadrails-65cd0fda2572ac9c78d8582496a9009d0c48df08.tar.gz
rails-65cd0fda2572ac9c78d8582496a9009d0c48df08.tar.bz2
rails-65cd0fda2572ac9c78d8582496a9009d0c48df08.zip
Fix inspect with non-primary key id attribute
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.
Diffstat (limited to 'activerecord/lib/active_record/core.rb')
-rw-r--r--activerecord/lib/active_record/core.rb4
1 files changed, 2 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb
index da3e2549a2..50f3087c51 100644
--- a/activerecord/lib/active_record/core.rb
+++ b/activerecord/lib/active_record/core.rb
@@ -498,7 +498,7 @@ module ActiveRecord
inspection = if defined?(@attributes) && @attributes
self.class.attribute_names.collect do |name|
if has_attribute?(name)
- attr = read_attribute(name)
+ attr = _read_attribute(name)
value = if attr.nil?
attr.inspect
else
@@ -528,7 +528,7 @@ module ActiveRecord
pp.text attr_name
pp.text ":"
pp.breakable
- value = read_attribute(attr_name)
+ value = _read_attribute(attr_name)
value = inspection_filter.filter_param(attr_name, value) unless value.nil?
pp.pp value
end