diff options
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/attribute_methods/dirty.rb | 1 | ||||
-rw-r--r-- | activerecord/lib/active_record/enum.rb | 26 |
2 files changed, 19 insertions, 8 deletions
diff --git a/activerecord/lib/active_record/attribute_methods/dirty.rb b/activerecord/lib/active_record/attribute_methods/dirty.rb index f7065d183f..68168bb729 100644 --- a/activerecord/lib/active_record/attribute_methods/dirty.rb +++ b/activerecord/lib/active_record/attribute_methods/dirty.rb @@ -45,7 +45,6 @@ module ActiveRecord save_changed_attribute(attr, value) - # Carry on. super(attr, value) end diff --git a/activerecord/lib/active_record/enum.rb b/activerecord/lib/active_record/enum.rb index 06e87cf854..0990a4a871 100644 --- a/activerecord/lib/active_record/enum.rb +++ b/activerecord/lib/active_record/enum.rb @@ -123,14 +123,26 @@ module ActiveRecord def _enum_methods_module @_enum_methods_module ||= begin mod = Module.new do - def save_changed_attribute(attr_name, value) - if self.class.enum_attribute?(attr_name) - old = clone_attribute_value(:read_attribute, attr_name) - changed_attributes[attr_name] = self.class.public_send(attr_name.pluralize).key old - else - super + private + def save_changed_attribute(attr_name, value) + if self.class.enum_attribute?(attr_name) + if attribute_changed?(attr_name) + old = changed_attributes[attr_name] + + if self.class.public_send(attr_name.pluralize)[old] == value + changed_attributes.delete(attr_name) + end + else + old = clone_attribute_value(:read_attribute, attr_name) + + if old != value + changed_attributes[attr_name] = self.class.public_send(attr_name.pluralize).key old + end + end + else + super + end end - end end include mod mod |