fix(dossier): safely remove child champs in apply_diff

This commit is contained in:
Paul Chavard 2024-03-11 09:17:03 +01:00
parent 94b4c8f46e
commit 72e27eb7b4

View file

@ -167,11 +167,12 @@ module DossierCloneConcern
end
champs_to_remove += diff[:removed]
champs_to_remove
.filter { !_1.child? || !champs_to_remove.include?(_1.parent) }
.each do |champ|
champ.rows.flatten.each(&:destroy!) if champ.repetition?
champ.destroy!
end
children_champs_to_remove, root_champs_to_remove = champs_to_remove.partition(&:child?)
children_champs_to_remove.each(&:destroy!)
root_champs_to_remove.each do |champ|
champ.rows.flatten.each(&:destroy!) if champ.repetition?
champ.destroy!
end
end
end