diff --git a/activerecord/lib/active_record/attribute_methods/read.rb b/activerecord/lib/active_record/attribute_methods/read.rb index bf2a084a00e7b57b4bfe8c48291ddd454bdb4dfe..55beb309cad7cd0c5d3049b458ec164f2c8e8dd4 100644 --- a/activerecord/lib/active_record/attribute_methods/read.rb +++ b/activerecord/lib/active_record/attribute_methods/read.rb @@ -76,12 +76,14 @@ def #{temp_method} end end + ID = 'id'.freeze + # Returns the value of the attribute identified by attr_name after # it has been typecast (for example, "2004-12-12" in a date column is cast # to a date object, like Date.new(2004, 12, 12)). def read_attribute(attr_name, &block) name = attr_name.to_s - name = self.class.primary_key if name == 'id' + name = self.class.primary_key if name == ID @attributes.fetch_value(name, &block) end