Replace attribute_changed? in before callbacks
This method is deprecated in Rails 5.1 because its behavior will be different in `before` and `after` callbacks. Here we're replacing the deprecated `attribute_changed?` and `attribute_was` with `will_save_change_to_attribute?` and `attribute_in_database` during `before_save` callbacks. https://github.com/rails/rails/pull/32835/
This commit is contained in:
@@ -396,7 +396,7 @@ class Budget
|
||||
private
|
||||
|
||||
def set_denormalized_ids
|
||||
self.group_id = heading&.group_id if heading_id_changed?
|
||||
self.group_id = heading&.group_id if will_save_change_to_heading_id?
|
||||
self.budget_id ||= heading&.group&.budget_id
|
||||
end
|
||||
|
||||
|
||||
@@ -19,10 +19,10 @@ class Poll::PartialResult < ApplicationRecord
|
||||
before_save :update_logs
|
||||
|
||||
def update_logs
|
||||
if amount_changed? && amount_was.present?
|
||||
self.amount_log += ":#{amount_was}"
|
||||
self.officer_assignment_id_log += ":#{officer_assignment_id_was}"
|
||||
self.author_id_log += ":#{author_id_was}"
|
||||
if will_save_change_to_amount? && amount_in_database.present?
|
||||
self.amount_log += ":#{amount_in_database}"
|
||||
self.officer_assignment_id_log += ":#{officer_assignment_id_in_database}"
|
||||
self.author_id_log += ":#{author_id_in_database}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -20,9 +20,9 @@ class Poll::Recount < ApplicationRecord
|
||||
amounts_changed = false
|
||||
|
||||
[:white, :null, :total].each do |amount|
|
||||
next unless send("#{amount}_amount_changed?") && send("#{amount}_amount_was").present?
|
||||
next unless send("will_save_change_to_#{amount}_amount?") && send("#{amount}_amount_in_database").present?
|
||||
|
||||
self["#{amount}_amount_log"] += ":#{send("#{amount}_amount_was")}"
|
||||
self["#{amount}_amount_log"] += ":#{send("#{amount}_amount_in_database")}"
|
||||
amounts_changed = true
|
||||
end
|
||||
|
||||
@@ -30,7 +30,7 @@ class Poll::Recount < ApplicationRecord
|
||||
end
|
||||
|
||||
def update_officer_author
|
||||
self.officer_assignment_id_log += ":#{officer_assignment_id_was}"
|
||||
self.author_id_log += ":#{author_id_was}"
|
||||
self.officer_assignment_id_log += ":#{officer_assignment_id_in_database}"
|
||||
self.author_id_log += ":#{author_id_in_database}"
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user