Include in exports types_de_champ from all revisions

This commit is contained in:
Paul Chavard 2020-09-08 15:53:07 +02:00
parent 8a2ae9d852
commit 1bd59c72e5
6 changed files with 117 additions and 27 deletions

View file

@ -50,7 +50,7 @@ class ProcedureRevision < ApplicationRecord
elsif type_de_champ.parent.present?
find_or_clone_type_de_champ(type_de_champ.parent.stable_id).types_de_champ.find_by!(stable_id: id)
else
type_de_champ.revise!
revise_type_de_champ(type_de_champ)
end
end
@ -98,6 +98,15 @@ class ProcedureRevision < ApplicationRecord
private
def revise_type_de_champ(type_de_champ)
types_de_champ_association = type_de_champ.private? ? :revision_types_de_champ_private : :revision_types_de_champ
association = send(types_de_champ_association).find_by!(type_de_champ: type_de_champ)
cloned_type_de_champ = type_de_champ.deep_clone(include: [:types_de_champ], &type_de_champ.method(:clone_attachments))
cloned_type_de_champ.revision = self
association.update!(type_de_champ: cloned_type_de_champ)
cloned_type_de_champ
end
def find_type_de_champ_by_id(id)
types_de_champ.find_by(stable_id: id) ||
types_de_champ_private.find_by(stable_id: id) ||