diff options
Diffstat (limited to 'activerecord/lib/active_record/attribute_methods/dirty.rb')
-rw-r--r-- | activerecord/lib/active_record/attribute_methods/dirty.rb | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/attribute_methods/dirty.rb b/activerecord/lib/active_record/attribute_methods/dirty.rb index 60e5b0e2bb..6204e4172d 100644 --- a/activerecord/lib/active_record/attribute_methods/dirty.rb +++ b/activerecord/lib/active_record/attribute_methods/dirty.rb @@ -64,15 +64,29 @@ module ActiveRecord end def update(*) + partial_updates? ? super(keys_for_partial_update) : super + end + + def create(*) if partial_updates? - # Serialized attributes should always be written in case they've been - # changed in place. - super(changed | (attributes.keys & self.class.serialized_attributes.keys)) + keys = keys_for_partial_update + + # This is an extremely bloody annoying necessity to work around mysql being crap. + # See test_mysql_text_not_null_defaults + keys.concat self.class.columns.select(&:explicit_default?).map(&:name) + + super keys else super end end + # Serialized attributes should always be written in case they've been + # changed in place. + def keys_for_partial_update + changed | (attributes.keys & self.class.serialized_attributes.keys) + end + def _field_changed?(attr, old, value) if column = column_for_attribute(attr) if column.number? && (changes_from_nil_to_empty_string?(column, old, value) || |