Link AssignTo et GroupeInstructeur
This commit is contained in:
parent
115d91387c
commit
97884c4349
6 changed files with 30 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
|||
class AssignTo < ApplicationRecord
|
||||
belongs_to :procedure
|
||||
belongs_to :instructeur
|
||||
belongs_to :groupe_instructeur
|
||||
has_one :procedure_presentation, dependent: :destroy
|
||||
|
||||
scope :with_email_notifications, -> { where(email_notifications_enabled: true) }
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
class GroupeInstructeur < ApplicationRecord
|
||||
DEFAULT_LABEL = 'défaut'
|
||||
belongs_to :procedure
|
||||
has_many :assign_tos
|
||||
has_many :instructeurs, through: :assign_tos
|
||||
end
|
||||
|
|
|
@ -7,6 +7,7 @@ class Instructeur < ApplicationRecord
|
|||
|
||||
has_many :assign_to, dependent: :destroy
|
||||
has_many :procedures, through: :assign_to
|
||||
has_many :groupe_instructeurs, through: :assign_to
|
||||
|
||||
has_many :assign_to_with_email_notifications, -> { with_email_notifications }, class_name: 'AssignTo', inverse_of: :instructeur
|
||||
has_many :procedures_with_email_notifications, through: :assign_to_with_email_notifications, source: :procedure
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
class AddGroupeInstructeurColumnToAssignTos < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_reference :assign_tos, :groupe_instructeur, foreign_key: true
|
||||
add_index :assign_tos, [:groupe_instructeur_id, :instructeur_id], unique: true, name: 'unique_couple_groupe_instructeur_instructeur'
|
||||
end
|
||||
end
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2019_08_19_134252) do
|
||||
ActiveRecord::Schema.define(version: 2019_08_19_145355) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
@ -118,6 +118,9 @@ ActiveRecord::Schema.define(version: 2019_08_19_134252) do
|
|||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.boolean "email_notifications_enabled", default: false, null: false
|
||||
t.bigint "groupe_instructeur_id"
|
||||
t.index ["groupe_instructeur_id", "instructeur_id"], name: "unique_couple_groupe_instructeur_instructeur", unique: true
|
||||
t.index ["groupe_instructeur_id"], name: "index_assign_tos_on_groupe_instructeur_id"
|
||||
t.index ["instructeur_id", "procedure_id"], name: "index_assign_tos_on_instructeur_id_and_procedure_id", unique: true
|
||||
t.index ["instructeur_id"], name: "index_assign_tos_on_instructeur_id"
|
||||
t.index ["procedure_id"], name: "index_assign_tos_on_procedure_id"
|
||||
|
@ -634,6 +637,7 @@ ActiveRecord::Schema.define(version: 2019_08_19_134252) do
|
|||
t.index ["procedure_id"], name: "index_without_continuation_mails_on_procedure_id"
|
||||
end
|
||||
|
||||
add_foreign_key "assign_tos", "groupe_instructeurs"
|
||||
add_foreign_key "attestation_templates", "procedures"
|
||||
add_foreign_key "attestations", "dossiers"
|
||||
add_foreign_key "avis", "instructeurs", column: "claimant_id"
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
namespace :after_party do
|
||||
desc 'Deployment task: link_assign_and_groupe_instructeur'
|
||||
task link_assign_and_groupe_instructeur: :environment do
|
||||
AssignTo.find_each do |at|
|
||||
GroupeInstructeur
|
||||
.find_by(procedure_id: at.procedure_id)
|
||||
&.assign_tos
|
||||
&.push(at)
|
||||
end
|
||||
|
||||
# Update task as completed. If you remove the line below, the task will
|
||||
# run with every deploy (or every time you call after_party:run).
|
||||
AfterParty::TaskRecord.create version: '20190819145528'
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue