aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-06-17 15:06:18 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-06-17 15:06:18 -0300
commitf55ea89e47a62192ef1a51e201e4a80dd52871d1 (patch)
tree360535d8e67af9b43cad174a68ae3ad411460c0b /activerecord
parent63b347df427ed2189fac7e75e36a3a4b9f6c2a68 (diff)
parentb301c40224c6d15b539dbcc7485adb44d810f88c (diff)
downloadrails-f55ea89e47a62192ef1a51e201e4a80dd52871d1.tar.gz
rails-f55ea89e47a62192ef1a51e201e4a80dd52871d1.tar.bz2
rails-f55ea89e47a62192ef1a51e201e4a80dd52871d1.zip
Merge pull request #15775 from sgrif/sg-use-column-defaults-in-dirty
Use `column_defaults` in dirty for checking changed defaults
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