wrap merge in transaction

This commit is contained in:
simon lehericey 2021-10-26 15:50:38 +02:00
parent 7935e42109
commit 8fe1e2bf71

View file

@ -196,6 +196,7 @@ class User < ApplicationRecord
end end
def merge(old_user) def merge(old_user)
transaction do
old_user.dossiers.update_all(user_id: id) old_user.dossiers.update_all(user_id: id)
old_user.invites.update_all(user_id: id) old_user.invites.update_all(user_id: id)
old_user.merge_logs.update_all(user_id: id) old_user.merge_logs.update_all(user_id: id)
@ -215,6 +216,7 @@ class User < ApplicationRecord
merge_logs.create(from_user_id: old_user.id, from_user_email: old_user.email) merge_logs.create(from_user_id: old_user.id, from_user_email: old_user.email)
old_user.destroy old_user.destroy
end end
end
private private