From 0f1b7591cf6cf30eb60cd4ccde1ca666225a95c3 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 7 Feb 2012 14:37:19 -0800 Subject: cache attribute if it is supposed to be cached --- activerecord/lib/active_record/attribute_methods/read.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/activerecord/lib/active_record/attribute_methods/read.rb b/activerecord/lib/active_record/attribute_methods/read.rb index a52d36aad8..0738c4c580 100644 --- a/activerecord/lib/active_record/attribute_methods/read.rb +++ b/activerecord/lib/active_record/attribute_methods/read.rb @@ -126,7 +126,11 @@ module ActiveRecord # "2004-12-12" in a data column is cast to a date object, like Date.new(2004, 12, 12)). def read_attribute(attr_name) if @columns_hash.key? attr_name - @columns_hash[attr_name].type_cast @attributes[attr_name] + if self.class.cache_attribute?(attr_name) + @attributes_cache[attr_name] ||= @columns_hash[attr_name].type_cast(@attributes[attr_name]) + else + @columns_hash[attr_name].type_cast @attributes[attr_name] + end else self.class.type_cast_attribute(attr_name, @attributes, @attributes_cache) end -- cgit v1.2.3