aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/attribute_methods.rb
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2013-04-28 12:03:26 +0200
committerXavier Noria <fxn@hashref.com>2013-04-28 12:03:59 +0200
commit607f136d52e984323cbe2938c04c660ca55a5039 (patch)
tree85eb7a2764caa5f0c872bc27fbddbae7178bf2a9 /activerecord/lib/active_record/attribute_methods.rb
parent31aab3ee57bc2cb31bcc0bf459c38b72d4ec3c24 (diff)
downloadrails-607f136d52e984323cbe2938c04c660ca55a5039.tar.gz
rails-607f136d52e984323cbe2938c04c660ca55a5039.tar.bz2
rails-607f136d52e984323cbe2938c04c660ca55a5039.zip
fixes a test, and explains why AR::AttributeMethods checks defined?(@attributes) in some places
Diffstat (limited to 'activerecord/lib/active_record/attribute_methods.rb')
-rw-r--r--activerecord/lib/active_record/attribute_methods.rb3
1 files changed, 3 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/attribute_methods.rb b/activerecord/lib/active_record/attribute_methods.rb
index 2fbab97133..609c6e8cab 100644
--- a/activerecord/lib/active_record/attribute_methods.rb
+++ b/activerecord/lib/active_record/attribute_methods.rb
@@ -172,6 +172,8 @@ module ActiveRecord
# If the result is true then check for the select case.
# For queries selecting a subset of columns, return false for unselected columns.
+ # We check defined?(@attributes) not to issue warnings if called on objects that
+ # have been allocated but not yet initialized.
if defined?(@attributes) && @attributes.present? && self.class.column_names.include?(name)
return has_attribute?(name)
end
@@ -340,6 +342,7 @@ module ActiveRecord
end
def attribute_method?(attr_name) # :nodoc:
+ # We check defined? because Syck calls respond_to? before actually calling initialize.
defined?(@attributes) && @attributes.include?(attr_name)
end