diff options
author | Sean Griffin <sean@thoughtbot.com> | 2014-05-30 15:57:42 -0700 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2014-06-03 09:33:46 -0600 |
commit | fb2a1c4b47800d6ed65662bed26fcdae66de5869 (patch) | |
tree | c4f0626c907f1bdc9b80521a2a81ff3552246104 /activerecord/lib/active_record/attribute_methods | |
parent | 5e15edfd1a197f450a02c314863106b6027dd0d1 (diff) | |
download | rails-fb2a1c4b47800d6ed65662bed26fcdae66de5869.tar.gz rails-fb2a1c4b47800d6ed65662bed26fcdae66de5869.tar.bz2 rails-fb2a1c4b47800d6ed65662bed26fcdae66de5869.zip |
Return a null column when no column exists for an attribute
Diffstat (limited to 'activerecord/lib/active_record/attribute_methods')
-rw-r--r-- | activerecord/lib/active_record/attribute_methods/dirty.rb | 3 | ||||
-rw-r--r-- | activerecord/lib/active_record/attribute_methods/write.rb | 12 |
2 files changed, 8 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/attribute_methods/dirty.rb b/activerecord/lib/active_record/attribute_methods/dirty.rb index 6cd4e43ddd..4e32b78e34 100644 --- a/activerecord/lib/active_record/attribute_methods/dirty.rb +++ b/activerecord/lib/active_record/attribute_methods/dirty.rb @@ -94,8 +94,7 @@ module ActiveRecord end def _field_changed?(attr, old, value) - column = column_for_attribute(attr) || Type::Value.new - column.changed?(old, value) + column_for_attribute(attr).changed?(old, value) end end end diff --git a/activerecord/lib/active_record/attribute_methods/write.rb b/activerecord/lib/active_record/attribute_methods/write.rb index c3e601a208..5203b30462 100644 --- a/activerecord/lib/active_record/attribute_methods/write.rb +++ b/activerecord/lib/active_record/attribute_methods/write.rb @@ -72,18 +72,20 @@ module ActiveRecord @attributes.delete(attr_name) column = column_for_attribute(attr_name) + unless has_attribute?(attr_name) || self.class.columns_hash.key?(attr_name) + raise ActiveModel::MissingAttributeError, "can't write unknown attribute `#{attr_name}'" + end + # If we're dealing with a binary column, write the data to the cache # so we don't attempt to typecast multiple times. - if column && column.binary? + if column.binary? @attributes[attr_name] = value end - if column && should_type_cast + if should_type_cast @raw_attributes[attr_name] = column.type_cast_for_write(value) - elsif !should_type_cast || @raw_attributes.has_key?(attr_name) - @raw_attributes[attr_name] = value else - raise ActiveModel::MissingAttributeError, "can't write unknown attribute `#{attr_name}'" + @raw_attributes[attr_name] = value end end end |