From b301c40224c6d15b539dbcc7485adb44d810f88c Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Tue, 17 Jun 2014 10:03:34 -0600 Subject: Use `column_defaults` in dirty for checking changed defaults We no longer need to "init changed attributes" from the initializer, either, as there is no longer a case where a given value would differ from the default, but would not already be marked as changed. --- activerecord/lib/active_record/attribute_methods/dirty.rb | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/attribute_methods/dirty.rb b/activerecord/lib/active_record/attribute_methods/dirty.rb index 9d1310b576..ca71834641 100644 --- a/activerecord/lib/active_record/attribute_methods/dirty.rb +++ b/activerecord/lib/active_record/attribute_methods/dirty.rb @@ -40,7 +40,7 @@ module ActiveRecord def initialize_dup(other) # :nodoc: super - init_changed_attributes + calculate_changes_from_defaults end def changed? @@ -71,17 +71,9 @@ module ActiveRecord private - def initialize_internals_callback - super - init_changed_attributes - end - - def init_changed_attributes + def calculate_changes_from_defaults @changed_attributes = nil - # Intentionally avoid using #column_defaults since overridden defaults (as is done in - # optimistic locking) won't get written unless they get marked as changed - self.class.columns.each do |c| - attr, orig_value = c.name, c.default + self.class.column_defaults.each do |attr, orig_value| changed_attributes[attr] = orig_value if _field_changed?(attr, orig_value) end end -- cgit v1.2.3