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