From 4aa573a75d82fba9473fd983d99aa67679aa5d6a Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Fri, 22 Oct 2021 10:55:10 +0200 Subject: [PATCH] fix(transfer): remove discarded dossiers from transfers --- app/models/dossier.rb | 1 + app/models/dossier_transfer.rb | 4 ++-- app/models/user.rb | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 6dcffed7c..92682a766 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -678,6 +678,7 @@ class Dossier < ApplicationRecord end end + update!(dossier_transfer_id: nil) discard! end diff --git a/app/models/dossier_transfer.rb b/app/models/dossier_transfer.rb index a033f7716..d2a6a3ac8 100644 --- a/app/models/dossier_transfer.rb +++ b/app/models/dossier_transfer.rb @@ -37,7 +37,7 @@ class DossierTransfer < ApplicationRecord } end) transfer.dossiers.update_all(user_id: current_user.id) - transfer.destroy + transfer.destroy_and_nullify end end @@ -48,7 +48,7 @@ class DossierTransfer < ApplicationRecord def destroy_and_nullify transaction do # Rails cascading is not working with default scopes. Doing nullify cascade manually. - Dossier.with_discarded.where(transfer: self).update_all(dossier_transfer_id: nil) + dossiers.with_discarded.update_all(dossier_transfer_id: nil) destroy end end diff --git a/app/models/user.rb b/app/models/user.rb index 32219d6b7..6b89c37f5 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -191,7 +191,7 @@ class User < ApplicationRecord .where.not(operation: DossierOperationLog.operations.fetch(:supprimer)) .destroy_all dossiers.with_discarded.discarded.destroy_all - dossiers.update_all(deleted_user_email_never_send: email, user_id: nil) + dossiers.update_all(deleted_user_email_never_send: email, user_id: nil, dossier_transfer_id: nil) destroy! end