aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/persistence.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/persistence.rb')
-rw-r--r--activerecord/lib/active_record/persistence.rb27
1 files changed, 16 insertions, 11 deletions
diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb
index ce16587326..7721e6b691 100644
--- a/activerecord/lib/active_record/persistence.rb
+++ b/activerecord/lib/active_record/persistence.rb
@@ -374,6 +374,7 @@ module ActiveRecord
became.send(:initialize)
became.instance_variable_set("@attributes", @attributes)
became.instance_variable_set("@mutations_from_database", @mutations_from_database) if defined?(@mutations_from_database)
+ became.instance_variable_set("@changed_attributes", attributes_changed_by_setter)
became.instance_variable_set("@new_record", new_record?)
became.instance_variable_set("@destroyed", destroyed?)
became.errors.copy!(errors)
@@ -656,18 +657,11 @@ module ActiveRecord
MSG
end
- time ||= current_time_from_proper_timezone
attribute_names = timestamp_attributes_for_update_in_model
- attribute_names.concat(names)
+ attribute_names |= names.map(&:to_s)
unless attribute_names.empty?
- attribute_names.each do |attr_name|
- write_attribute(attr_name, time)
- clear_attribute_change(attr_name)
- end
-
- affected_rows = _update_row(attribute_names, "touch")
-
+ affected_rows = _touch_row(attribute_names, time)
@_trigger_update_callback = affected_rows == 1
else
true
@@ -688,7 +682,18 @@ module ActiveRecord
self.class._delete_record(self.class.primary_key => id_in_database)
end
- def _update_row(attribute_names, attempted_action)
+ def _touch_row(attribute_names, time)
+ time ||= current_time_from_proper_timezone
+
+ attribute_names.each do |attr_name|
+ write_attribute(attr_name, time)
+ clear_attribute_change(attr_name)
+ end
+
+ _update_row(attribute_names, "touch")
+ end
+
+ def _update_row(attribute_names, attempted_action = "update")
self.class._update_record(
attributes_with_values(attribute_names),
self.class.primary_key => id_in_database
@@ -712,7 +717,7 @@ module ActiveRecord
affected_rows = 0
@_trigger_update_callback = true
else
- affected_rows = _update_row(attribute_names, "update")
+ affected_rows = _update_row(attribute_names)
@_trigger_update_callback = affected_rows == 1
end