diff options
author | Yves Senn <yves.senn@gmail.com> | 2014-06-01 22:24:01 +0200 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2014-06-01 22:24:01 +0200 |
commit | 02ee081cd645b51cbdfb28cd305777d3257ad871 (patch) | |
tree | 1b02b3ccffbef9296aaa6660caed5c64fcb362aa /activerecord/lib/active_record/attribute_methods/write.rb | |
parent | 260c384bdb539265b31d3937df48e528acb50800 (diff) | |
parent | 90c8be76a7d00475be5ff4db2eeedde5cc936c2d (diff) | |
download | rails-02ee081cd645b51cbdfb28cd305777d3257ad871.tar.gz rails-02ee081cd645b51cbdfb28cd305777d3257ad871.tar.bz2 rails-02ee081cd645b51cbdfb28cd305777d3257ad871.zip |
Merge pull request #15435 from sgrif/sg-rm-serialization
Remove most code related to serialized properties
Diffstat (limited to 'activerecord/lib/active_record/attribute_methods/write.rb')
-rw-r--r-- | activerecord/lib/active_record/attribute_methods/write.rb | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/attribute_methods/write.rb b/activerecord/lib/active_record/attribute_methods/write.rb index 3b9b9c81e8..c3e601a208 100644 --- a/activerecord/lib/active_record/attribute_methods/write.rb +++ b/activerecord/lib/active_record/attribute_methods/write.rb @@ -53,11 +53,11 @@ module ActiveRecord # specified +value+. Empty strings for fixnum and float columns are # turned into +nil+. def write_attribute(attr_name, value) - write_attribute_with_type_cast(attr_name, value, :type_cast_for_write) + write_attribute_with_type_cast(attr_name, value, true) end def raw_write_attribute(attr_name, value) - write_attribute_with_type_cast(attr_name, value, :raw_type_cast_for_write) + write_attribute_with_type_cast(attr_name, value, false) end private @@ -66,7 +66,7 @@ module ActiveRecord write_attribute(attribute_name, value) end - def write_attribute_with_type_cast(attr_name, value, type_cast_method) + def write_attribute_with_type_cast(attr_name, value, should_type_cast) attr_name = attr_name.to_s attr_name = self.class.primary_key if attr_name == 'id' && self.class.primary_key @attributes.delete(attr_name) @@ -78,9 +78,9 @@ module ActiveRecord @attributes[attr_name] = value end - if column - @raw_attributes[attr_name] = column.public_send(type_cast_method, value) - elsif @raw_attributes.has_key?(attr_name) + if column && 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}'" |