aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/attribute_methods
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2012-02-07 14:37:19 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2012-02-07 14:37:19 -0800
commit0f1b7591cf6cf30eb60cd4ccde1ca666225a95c3 (patch)
treede9411afb0d6d6dc9dade77a6d00ce27b16d6115 /activerecord/lib/active_record/attribute_methods
parent2927007be8f5de038519158ce5f4125824152993 (diff)
downloadrails-0f1b7591cf6cf30eb60cd4ccde1ca666225a95c3.tar.gz
rails-0f1b7591cf6cf30eb60cd4ccde1ca666225a95c3.tar.bz2
rails-0f1b7591cf6cf30eb60cd4ccde1ca666225a95c3.zip
cache attribute if it is supposed to be cached
Diffstat (limited to 'activerecord/lib/active_record/attribute_methods')
-rw-r--r--activerecord/lib/active_record/attribute_methods/read.rb6
1 files changed, 5 insertions, 1 deletions
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