wrap merge in transaction
This commit is contained in:
parent
7935e42109
commit
8fe1e2bf71
1 changed files with 17 additions and 15 deletions
|
@ -196,24 +196,26 @@ class User < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def merge(old_user)
|
def merge(old_user)
|
||||||
old_user.dossiers.update_all(user_id: id)
|
transaction do
|
||||||
old_user.invites.update_all(user_id: id)
|
old_user.dossiers.update_all(user_id: id)
|
||||||
old_user.merge_logs.update_all(user_id: id)
|
old_user.invites.update_all(user_id: id)
|
||||||
|
old_user.merge_logs.update_all(user_id: id)
|
||||||
|
|
||||||
[
|
[
|
||||||
[old_user.instructeur, instructeur],
|
[old_user.instructeur, instructeur],
|
||||||
[old_user.expert, expert],
|
[old_user.expert, expert],
|
||||||
[old_user.administrateur, administrateur]
|
[old_user.administrateur, administrateur]
|
||||||
].each do |old_role, targeted_role|
|
].each do |old_role, targeted_role|
|
||||||
if targeted_role.nil?
|
if targeted_role.nil?
|
||||||
old_role&.update(user: self)
|
old_role&.update(user: self)
|
||||||
else
|
else
|
||||||
targeted_role.merge(old_role)
|
targeted_role.merge(old_role)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
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
|
||||||
|
|
Loading…
Reference in a new issue