From 65cd0fda2572ac9c78d8582496a9009d0c48df08 Mon Sep 17 00:00:00 2001 From: Eugene Kenny Date: Tue, 6 Nov 2018 01:51:52 +0000 Subject: 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. --- activerecord/test/models/topic.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'activerecord/test/models') diff --git a/activerecord/test/models/topic.rb b/activerecord/test/models/topic.rb index 4aad6a4498..03430154db 100644 --- a/activerecord/test/models/topic.rb +++ b/activerecord/test/models/topic.rb @@ -138,6 +138,10 @@ class BlankTopic < Topic end end +class TitlePrimaryKeyTopic < Topic + self.primary_key = :title +end + module Web class Topic < ActiveRecord::Base has_many :replies, dependent: :destroy, foreign_key: "parent_id", class_name: "Web::Reply" -- cgit v1.2.3