fix(revision): fix migrate_parent!
This commit is contained in:
parent
3d7356c2d0
commit
6adb3f7a3a
3 changed files with 18 additions and 9 deletions
|
@ -732,6 +732,13 @@ class Procedure < ApplicationRecord
|
||||||
|
|
||||||
new_draft.revision_types_de_champ.reload
|
new_draft.revision_types_de_champ.reload
|
||||||
|
|
||||||
|
# Some revisions do not have links to children types de champ
|
||||||
|
new_draft
|
||||||
|
.types_de_champ
|
||||||
|
.filter(&:repetition?)
|
||||||
|
.flat_map(&:types_de_champ)
|
||||||
|
.each(&:migrate_parent!)
|
||||||
|
|
||||||
new_draft
|
new_draft
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -381,13 +381,12 @@ class ProcedureRevision < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def revise_type_de_champ(type_de_champ)
|
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_public
|
revision_type_de_champ = revision_types_de_champ.find_by!(type_de_champ: type_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]) do |original, kopy|
|
cloned_type_de_champ = type_de_champ.deep_clone(include: [:types_de_champ]) do |original, kopy|
|
||||||
PiecesJustificativesService.clone_attachments(original, kopy)
|
PiecesJustificativesService.clone_attachments(original, kopy)
|
||||||
end
|
end
|
||||||
cloned_type_de_champ.revision = self
|
cloned_type_de_champ.revision = self
|
||||||
association.update!(type_de_champ: cloned_type_de_champ)
|
revision_type_de_champ.update!(type_de_champ: cloned_type_de_champ)
|
||||||
cloned_type_de_champ.types_de_champ.each(&:migrate_parent!)
|
cloned_type_de_champ.types_de_champ.each(&:migrate_parent!)
|
||||||
cloned_type_de_champ
|
cloned_type_de_champ
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
# stable_id :bigint
|
# stable_id :bigint
|
||||||
#
|
#
|
||||||
class TypeDeChamp < ApplicationRecord
|
class TypeDeChamp < ApplicationRecord
|
||||||
|
self.ignored_columns = [:migrated_parent]
|
||||||
|
|
||||||
enum type_champs: {
|
enum type_champs: {
|
||||||
text: 'text',
|
text: 'text',
|
||||||
textarea: 'textarea',
|
textarea: 'textarea',
|
||||||
|
@ -394,12 +396,13 @@ class TypeDeChamp < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def migrate_parent!
|
def migrate_parent!
|
||||||
if parent_id.present? && migrated_parent.nil?
|
if parent_id.present? && revision_types_de_champ.empty?
|
||||||
ProcedureRevisionTypeDeChamp.create(parent: parent.revision_type_de_champ,
|
parent.revision_types_de_champ.each do |revision_type_de_champ|
|
||||||
type_de_champ: self,
|
ProcedureRevisionTypeDeChamp.create(parent: revision_type_de_champ,
|
||||||
revision_id: parent.revision_type_de_champ.revision_id,
|
type_de_champ: self,
|
||||||
position: order_place)
|
revision_id: revision_type_de_champ.revision_id,
|
||||||
update_column(:migrated_parent, true)
|
position: order_place)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue