add expert to avis table

This commit is contained in:
kara Diaby 2021-01-15 16:39:07 +01:00
parent efbff0f2e0
commit b683c2023b
4 changed files with 25 additions and 13 deletions

View file

@ -2,27 +2,30 @@
# #
# Table name: avis # Table name: avis
# #
# id :integer not null, primary key # id :integer not null, primary key
# answer :text # answer :text
# confidentiel :boolean default(FALSE), not null # confidentiel :boolean default(FALSE), not null
# email :string # email :string
# introduction :text # introduction :text
# revoked_at :datetime # revoked_at :datetime
# created_at :datetime not null # created_at :datetime not null
# updated_at :datetime not null # updated_at :datetime not null
# claimant_id :integer not null # claimant_id :integer not null
# dossier_id :integer # dossier_id :integer
# instructeur_id :integer # experts_procedure_id :bigint
# instructeur_id :integer
# #
class Avis < ApplicationRecord class Avis < ApplicationRecord
include EmailSanitizableConcern include EmailSanitizableConcern
belongs_to :dossier, inverse_of: :avis, touch: true, optional: false belongs_to :dossier, inverse_of: :avis, touch: true, optional: false
belongs_to :instructeur, optional: true belongs_to :instructeur, optional: true
belongs_to :experts_procedure, optional: true
belongs_to :claimant, class_name: 'Instructeur', optional: false belongs_to :claimant, class_name: 'Instructeur', optional: false
has_one_attached :piece_justificative_file has_one_attached :piece_justificative_file
has_one_attached :introduction_file has_one_attached :introduction_file
has_one :expert, through: :experts_procedure
validates :piece_justificative_file, validates :piece_justificative_file,
content_type: AUTHORIZED_CONTENT_TYPES, content_type: AUTHORIZED_CONTENT_TYPES,

View file

@ -12,5 +12,6 @@
class ExpertsProcedure < ApplicationRecord class ExpertsProcedure < ApplicationRecord
belongs_to :expert belongs_to :expert
belongs_to :procedure belongs_to :procedure
validates :expert, uniqueness: { scope: :procedure }
has_many :avis, dependent: :destroy
end end

View file

@ -0,0 +1,5 @@
class AddExpertsProcedureToAvis < ActiveRecord::Migration[6.0]
def change
add_reference :avis, :experts_procedure, foreign_key: true
end
end

View file

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_01_13_150013) do ActiveRecord::Schema.define(version: 2021_01_13_084256) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -121,8 +121,10 @@ ActiveRecord::Schema.define(version: 2021_01_13_150013) do
t.integer "claimant_id", null: false t.integer "claimant_id", null: false
t.boolean "confidentiel", default: false, null: false t.boolean "confidentiel", default: false, null: false
t.datetime "revoked_at" t.datetime "revoked_at"
t.bigint "experts_procedure_id"
t.index ["claimant_id"], name: "index_avis_on_claimant_id" t.index ["claimant_id"], name: "index_avis_on_claimant_id"
t.index ["dossier_id"], name: "index_avis_on_dossier_id" t.index ["dossier_id"], name: "index_avis_on_dossier_id"
t.index ["experts_procedure_id"], name: "index_avis_on_experts_procedure_id"
t.index ["instructeur_id"], name: "index_avis_on_instructeur_id" t.index ["instructeur_id"], name: "index_avis_on_instructeur_id"
end end
@ -723,6 +725,7 @@ ActiveRecord::Schema.define(version: 2021_01_13_150013) do
add_foreign_key "assign_tos", "groupe_instructeurs" add_foreign_key "assign_tos", "groupe_instructeurs"
add_foreign_key "attestation_templates", "procedures" add_foreign_key "attestation_templates", "procedures"
add_foreign_key "attestations", "dossiers" add_foreign_key "attestations", "dossiers"
add_foreign_key "avis", "experts_procedures"
add_foreign_key "avis", "instructeurs", column: "claimant_id" add_foreign_key "avis", "instructeurs", column: "claimant_id"
add_foreign_key "champs", "champs", column: "parent_id" add_foreign_key "champs", "champs", column: "parent_id"
add_foreign_key "closed_mails", "procedures" add_foreign_key "closed_mails", "procedures"