From 5dd8bbe7975aee8b9a215e0e4cedc322057d77e2 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Fri, 6 May 2022 09:39:14 +0200 Subject: [PATCH] fix remove type de champ --- app/models/procedure_revision.rb | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/app/models/procedure_revision.rb b/app/models/procedure_revision.rb index 59dc5b344..492788145 100644 --- a/app/models/procedure_revision.rb +++ b/app/models/procedure_revision.rb @@ -86,14 +86,16 @@ class ProcedureRevision < ApplicationRecord end def remove_type_de_champ(stable_id) - type_de_champ = find_type_de_champ_by_stable_id(stable_id) + coordinate = revision_types_de_champ + .joins(:type_de_champ) + .find_by(type_de_champ: { stable_id: stable_id }) - if type_de_champ.only_present_on_draft? - type_de_champ.destroy - elsif type_de_champ.parent.present? - find_or_clone_type_de_champ(stable_id).destroy - else - types_de_champ.delete(type_de_champ) + tdc = coordinate.type_de_champ + + coordinate.destroy + + if tdc.revision_types_de_champ.empty? + tdc.destroy end end