Merge pull request #7307 from tchak/refactor-type-de-champ-revision
refactor(revision): remove type_de_champ#revision_id
This commit is contained in:
commit
5aaef15c67
6 changed files with 9 additions and 22 deletions
|
@ -498,11 +498,7 @@ class Procedure < ApplicationRecord
|
|||
end
|
||||
|
||||
procedure.save
|
||||
procedure.draft_types_de_champ.update_all(revision_id: procedure.draft_revision.id)
|
||||
procedure.draft_types_de_champ_private.update_all(revision_id: procedure.draft_revision.id)
|
||||
types_de_champ_in_repetition = TypeDeChamp.where(parent: procedure.draft_types_de_champ.repetition + procedure.draft_types_de_champ_private.repetition)
|
||||
types_de_champ_in_repetition.update_all(revision_id: procedure.draft_revision.id)
|
||||
types_de_champ_in_repetition.each(&:migrate_parent!)
|
||||
TypeDeChamp.where(parent: procedure.draft_revision.types_de_champ.repetition).find_each(&:migrate_parent!)
|
||||
|
||||
if is_different_admin || from_library
|
||||
procedure.draft_types_de_champ.each { |tdc| tdc.options&.delete(:old_pj) }
|
||||
|
|
|
@ -25,7 +25,6 @@ class ProcedureRevision < ApplicationRecord
|
|||
has_many :types_de_champ_public, through: :revision_types_de_champ_public, source: :type_de_champ
|
||||
has_many :types_de_champ_private, through: :revision_types_de_champ_private, source: :type_de_champ
|
||||
|
||||
has_many :owned_types_de_champ, class_name: 'TypeDeChamp', foreign_key: :revision_id, dependent: :destroy, inverse_of: :revision
|
||||
has_one :draft_procedure, -> { with_discarded }, class_name: 'Procedure', foreign_key: :draft_revision_id, dependent: :nullify, inverse_of: :draft_revision
|
||||
has_one :published_procedure, -> { with_discarded }, class_name: 'Procedure', foreign_key: :published_revision_id, dependent: :nullify, inverse_of: :published_revision
|
||||
|
||||
|
@ -40,8 +39,6 @@ class ProcedureRevision < ApplicationRecord
|
|||
end
|
||||
|
||||
def add_type_de_champ(params)
|
||||
params[:revision] = self
|
||||
|
||||
if params[:parent_id]
|
||||
find_or_clone_type_de_champ(params.delete(:parent_id))
|
||||
.types_de_champ
|
||||
|
@ -398,7 +395,6 @@ class ProcedureRevision < ApplicationRecord
|
|||
cloned_type_de_champ = type_de_champ.deep_clone(include: [:types_de_champ]) do |original, kopy|
|
||||
PiecesJustificativesService.clone_attachments(original, kopy)
|
||||
end
|
||||
cloned_type_de_champ.revision = self
|
||||
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
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
# stable_id :bigint
|
||||
#
|
||||
class TypeDeChamp < ApplicationRecord
|
||||
self.ignored_columns = [:migrated_parent]
|
||||
self.ignored_columns = [:migrated_parent, :revision_id]
|
||||
|
||||
enum type_champs: {
|
||||
text: 'text',
|
||||
|
@ -58,9 +58,6 @@ class TypeDeChamp < ApplicationRecord
|
|||
mesri: 'mesri'
|
||||
}
|
||||
|
||||
belongs_to :revision, class_name: 'ProcedureRevision', optional: true
|
||||
has_one :procedure, through: :revision
|
||||
|
||||
belongs_to :parent, class_name: 'TypeDeChamp', optional: true
|
||||
has_many :types_de_champ, -> { ordered }, foreign_key: :parent_id, class_name: 'TypeDeChamp', inverse_of: :parent, dependent: :destroy
|
||||
|
||||
|
@ -68,6 +65,8 @@ class TypeDeChamp < ApplicationRecord
|
|||
has_many :revision_types_de_champ, -> { revision_ordered }, class_name: 'ProcedureRevisionTypeDeChamp', dependent: :destroy, inverse_of: :type_de_champ
|
||||
has_one :revision_type_de_champ, -> { revision_ordered }, class_name: 'ProcedureRevisionTypeDeChamp', inverse_of: false
|
||||
has_many :revisions, -> { ordered }, through: :revision_types_de_champ
|
||||
has_one :revision, through: :revision_type_de_champ
|
||||
has_one :procedure, through: :revision
|
||||
|
||||
delegate :tags_for_template, :libelle_for_export, to: :dynamic_type
|
||||
|
||||
|
|
|
@ -354,9 +354,8 @@ def add_types_de_champs(types_de_champ, to: nil, scope: :public)
|
|||
association_name = scope == :private ? :revision_types_de_champ_private : :revision_types_de_champ_public
|
||||
|
||||
types_de_champ.each do |type_de_champ|
|
||||
type_de_champ.revision = revision
|
||||
type_de_champ.private = (scope == :private)
|
||||
type_de_champ.revision.public_send(association_name) << build(:procedure_revision_type_de_champ,
|
||||
revision.public_send(association_name) << build(:procedure_revision_type_de_champ,
|
||||
revision: revision,
|
||||
position: type_de_champ.order_place,
|
||||
type_de_champ: type_de_champ)
|
||||
|
|
|
@ -15,20 +15,19 @@ FactoryBot.define do
|
|||
|
||||
after(:build) do |type_de_champ, evaluator|
|
||||
if evaluator.procedure
|
||||
type_de_champ.revision = evaluator.procedure.active_revision
|
||||
revision = evaluator.procedure.active_revision
|
||||
|
||||
build(:procedure_revision_type_de_champ,
|
||||
position: evaluator.position,
|
||||
revision: evaluator.procedure.active_revision,
|
||||
revision: revision,
|
||||
type_de_champ: type_de_champ)
|
||||
|
||||
if type_de_champ.private?
|
||||
type_de_champ.revision.types_de_champ_private << type_de_champ
|
||||
revision.types_de_champ_private << type_de_champ
|
||||
else
|
||||
type_de_champ.revision.types_de_champ_public << type_de_champ
|
||||
revision.types_de_champ_public << type_de_champ
|
||||
end
|
||||
elsif evaluator.parent
|
||||
type_de_champ.revision = evaluator.parent.revision
|
||||
type_de_champ.order_place = evaluator.position || evaluator.parent.types_de_champ.size
|
||||
evaluator.parent.types_de_champ << type_de_champ
|
||||
else
|
||||
|
@ -181,7 +180,6 @@ FactoryBot.define do
|
|||
|
||||
after(:build) do |type_de_champ_repetition, evaluator|
|
||||
evaluator.types_de_champ.each do |type_de_champ|
|
||||
type_de_champ.revision = type_de_champ_repetition.revision
|
||||
type_de_champ.order_place = type_de_champ_repetition.types_de_champ.size
|
||||
type_de_champ_repetition.types_de_champ << type_de_champ
|
||||
end
|
||||
|
|
|
@ -320,7 +320,6 @@ describe Procedure do
|
|||
procedure.validate
|
||||
expect(procedure.errors.full_messages_for(:draft_types_de_champ)).to include(invalid_repetition_error_message)
|
||||
|
||||
text_field.revision = repetition.revision
|
||||
text_field.order_place = repetition.types_de_champ.size
|
||||
procedure.draft_types_de_champ.find(&:repetition?).types_de_champ << text_field
|
||||
|
||||
|
|
Loading…
Reference in a new issue