aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/attribute_methods
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-04-15 13:27:08 +0100
committerJon Leighton <j@jonathanleighton.com>2011-04-15 13:27:08 +0100
commit65469a6e5e8cd2418c99c3862dd33feed69536bd (patch)
tree68a2ba51dba0b182179652851706096b9cb33f58 /activerecord/lib/active_record/attribute_methods
parente01dfb27fc5573db9070dce788f2e5ee62094722 (diff)
downloadrails-65469a6e5e8cd2418c99c3862dd33feed69536bd.tar.gz
rails-65469a6e5e8cd2418c99c3862dd33feed69536bd.tar.bz2
rails-65469a6e5e8cd2418c99c3862dd33feed69536bd.zip
Return nil from read_attribute(:foo) if 'foo' is not present in the @attributes hash, but the _foo method has been defined. This brings the behaviour into line with the 3-0-stable branch and the master branch before 93641ed6c8c684f6b4db02b6c8a22fa9bc7f0eaf (there were previously no assertions about this which is why the change slipped through). Note that actually calling the 'foo' method will still raise an error if the attribute is not present.
Diffstat (limited to 'activerecord/lib/active_record/attribute_methods')
-rw-r--r--activerecord/lib/active_record/attribute_methods/read.rb2
1 files changed, 1 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/attribute_methods/read.rb b/activerecord/lib/active_record/attribute_methods/read.rb
index cd6c4002d2..a248eb3a7b 100644
--- a/activerecord/lib/active_record/attribute_methods/read.rb
+++ b/activerecord/lib/active_record/attribute_methods/read.rb
@@ -100,7 +100,7 @@ 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 respond_to? "_#{attr_name}"
- send "_#{attr_name}"
+ send "_#{attr_name}" if @attributes.has_key?(attr_name.to_s)
else
_read_attribute attr_name
end