fix(relation): avoid double association between procedure/procedure_revision/dossier_submitted_message
This commit is contained in:
parent
35b9487897
commit
b808b4db00
5 changed files with 3 additions and 10 deletions
|
@ -31,7 +31,7 @@ module Administrateurs
|
|||
|
||||
# for now, only works on active revision no matter the procedure_revision_policy
|
||||
def build_dossier_submitted_message(attributes = {})
|
||||
dossier_submitted_message = @procedure.active_revision.dossier_submitted_message || @procedure.active_revision.build_dossier_submitted_message(procedure_id: @procedure.id)
|
||||
dossier_submitted_message = @procedure.active_revision.dossier_submitted_message || @procedure.active_revision.build_dossier_submitted_message
|
||||
|
||||
dossier_submitted_message.attributes = attributes unless attributes.empty?
|
||||
dossier_submitted_message
|
||||
|
|
|
@ -6,9 +6,7 @@
|
|||
# message_on_submit_by_usager :string
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# procedure_id :bigint not null
|
||||
#
|
||||
class DossierSubmittedMessage < ApplicationRecord
|
||||
belongs_to :procedure
|
||||
has_many :revisions, class_name: 'ProcedureRevision', inverse_of: :dossier_submitted_message, dependent: :nullify
|
||||
end
|
||||
|
|
|
@ -2,10 +2,8 @@ class CreateDossierSubmittedMessages < ActiveRecord::Migration[6.1]
|
|||
def change
|
||||
create_table :dossier_submitted_messages do |t|
|
||||
t.string :message_on_submit_by_usager
|
||||
t.references :procedure, null: false, index: true
|
||||
t.timestamps
|
||||
end
|
||||
add_reference :procedure_revisions, :dossier_submitted_message, foreign_key: { to_table: :dossier_submitted_messages }, null: true, index: true
|
||||
add_foreign_key :dossier_submitted_messages, :procedures
|
||||
end
|
||||
end
|
||||
|
|
|
@ -277,10 +277,8 @@ ActiveRecord::Schema.define(version: 2022_02_04_130722) do
|
|||
|
||||
create_table "dossier_submitted_messages", force: :cascade do |t|
|
||||
t.string "message_on_submit_by_usager"
|
||||
t.bigint "procedure_id", null: false
|
||||
t.datetime "created_at", precision: 6, null: false
|
||||
t.datetime "updated_at", precision: 6, null: false
|
||||
t.index ["procedure_id"], name: "index_dossier_submitted_messages_on_procedure_id"
|
||||
end
|
||||
|
||||
create_table "dossier_transfer_logs", force: :cascade do |t|
|
||||
|
@ -602,8 +600,8 @@ ActiveRecord::Schema.define(version: 2022_02_04_130722) do
|
|||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.datetime "published_at"
|
||||
t.bigint "dossier_submitted_message_id"
|
||||
t.bigint "attestation_template_id"
|
||||
t.bigint "dossier_submitted_message_id"
|
||||
t.index ["attestation_template_id"], name: "index_procedure_revisions_on_attestation_template_id"
|
||||
t.index ["dossier_submitted_message_id"], name: "index_procedure_revisions_on_dossier_submitted_message_id"
|
||||
t.index ["procedure_id"], name: "index_procedure_revisions_on_procedure_id"
|
||||
|
@ -869,7 +867,6 @@ ActiveRecord::Schema.define(version: 2022_02_04_130722) do
|
|||
add_foreign_key "commentaires", "experts"
|
||||
add_foreign_key "dossier_operation_logs", "bill_signatures"
|
||||
add_foreign_key "dossier_operation_logs", "instructeurs"
|
||||
add_foreign_key "dossier_submitted_messages", "procedures"
|
||||
add_foreign_key "dossier_transfer_logs", "dossiers"
|
||||
add_foreign_key "dossiers", "dossier_transfers"
|
||||
add_foreign_key "dossiers", "groupe_instructeurs"
|
||||
|
|
|
@ -323,7 +323,7 @@ FactoryBot.define do
|
|||
|
||||
trait :with_dossier_submitted_message do
|
||||
after(:build) do |procedure, _evaluator|
|
||||
build(:dossier_submitted_message, procedure: procedure, revisions: [procedure.active_revision])
|
||||
build(:dossier_submitted_message, revisions: [procedure.active_revision])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue