Post#give_favorites_to_parent: wrap in transaction.

Ensure that if anything fails then the entire favorites move will be
rolled back.
This commit is contained in:
evazion
2017-04-04 20:31:20 -05:00
parent 40feeb2411
commit c03aa79ece

View File

@@ -1282,9 +1282,11 @@ class Post < ActiveRecord::Base
def give_favorites_to_parent
return if parent.nil?
favorites.each do |fav|
remove_favorite!(fav.user)
parent.add_favorite!(fav.user)
transaction do
favorites.each do |fav|
remove_favorite!(fav.user)
parent.add_favorite!(fav.user)
end
end
end