aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2014-06-17 10:03:34 -0600
committerSean Griffin <sean@thoughtbot.com>2014-06-17 12:00:57 -0600
commitb301c40224c6d15b539dbcc7485adb44d810f88c (patch)
tree360535d8e67af9b43cad174a68ae3ad411460c0b /activerecord
parent63b347df427ed2189fac7e75e36a3a4b9f6c2a68 (diff)
downloadrails-b301c40224c6d15b539dbcc7485adb44d810f88c.tar.gz
rails-b301c40224c6d15b539dbcc7485adb44d810f88c.tar.bz2
rails-b301c40224c6d15b539dbcc7485adb44d810f88c.zip
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.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/attribute_methods/dirty.rb14
1 files changed, 3 insertions, 11 deletions
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