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:
@@ -1282,9 +1282,11 @@ class Post < ActiveRecord::Base
|
|||||||
def give_favorites_to_parent
|
def give_favorites_to_parent
|
||||||
return if parent.nil?
|
return if parent.nil?
|
||||||
|
|
||||||
favorites.each do |fav|
|
transaction do
|
||||||
remove_favorite!(fav.user)
|
favorites.each do |fav|
|
||||||
parent.add_favorite!(fav.user)
|
remove_favorite!(fav.user)
|
||||||
|
parent.add_favorite!(fav.user)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user