fix remove type de champ

This commit is contained in:
simon lehericey 2022-05-06 09:39:14 +02:00
parent 6bf52b1f99
commit 5dd8bbe797

View file

@ -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