From 7dd7d76b86b2168b39fb7f0c359d84ea6df0ce41 Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Fri, 30 Mar 2012 11:09:27 +0100 Subject: recurse in read_attribute we get caching / don't duplicate code --- activerecord/lib/active_record/attribute_methods/read.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/attribute_methods/read.rb b/activerecord/lib/active_record/attribute_methods/read.rb index d108de385f..dcc3d79de9 100644 --- a/activerecord/lib/active_record/attribute_methods/read.rb +++ b/activerecord/lib/active_record/attribute_methods/read.rb @@ -67,9 +67,8 @@ module ActiveRecord @attributes_cache.fetch(attr_name.to_s) { |name| column = @columns_hash.fetch(name) { return @attributes.fetch(name) { - if name == 'id' - primary_key = self.class.primary_key - @columns_hash[primary_key].type_cast(@attributes[primary_key]) + if name == 'id' && self.class.primary_key != name + read_attribute(self.class.primary_key) end } } -- cgit v1.2.3