diff --git a/app/models/administrateur.rb b/app/models/administrateur.rb index 94c0498f0..790f1062e 100644 --- a/app/models/administrateur.rb +++ b/app/models/administrateur.rb @@ -7,6 +7,8 @@ class Administrateur < ApplicationRecord has_and_belongs_to_many :gestionnaires has_many :procedures + has_many :administrateurs_procedures + has_many :admin_procedures, through: :administrateurs_procedures, source: :procedure before_validation -> { sanitize_email(:email) } before_save :ensure_api_token diff --git a/app/models/administrateurs_procedure.rb b/app/models/administrateurs_procedure.rb new file mode 100644 index 000000000..084a18781 --- /dev/null +++ b/app/models/administrateurs_procedure.rb @@ -0,0 +1,4 @@ +class AdministrateursProcedure < ApplicationRecord + belongs_to :administrateur + belongs_to :procedure +end diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 3e1378feb..745298119 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -12,6 +12,8 @@ class Procedure < ApplicationRecord belongs_to :administrateur has_many :assign_to, dependent: :destroy + has_many :administrateurs_procedures + has_many :administrateurs, through: :administrateurs_procedures has_many :gestionnaires, through: :assign_to has_one :initiated_mail, class_name: "Mails::InitiatedMail", dependent: :destroy diff --git a/db/migrate/20180323101837_create_join_table_administrateurs_procedures.rb b/db/migrate/20180323101837_create_join_table_administrateurs_procedures.rb new file mode 100644 index 000000000..a77186ac5 --- /dev/null +++ b/db/migrate/20180323101837_create_join_table_administrateurs_procedures.rb @@ -0,0 +1,11 @@ +class CreateJoinTableAdministrateursProcedures < ActiveRecord::Migration[5.2] + def change + create_join_table :administrateurs, :procedures do |t| + t.timestamps + + t.index :administrateur_id + t.index :procedure_id + t.index [:administrateur_id, :procedure_id], unique: true, name: :index_unique_admin_proc_couple + end + end +end diff --git a/db/schema.rb b/db/schema.rb index a24ff0efa..0e708a7fe 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2018_03_19_214757) do +ActiveRecord::Schema.define(version: 2018_03_23_101837) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -64,6 +64,16 @@ ActiveRecord::Schema.define(version: 2018_03_19_214757) do t.index ["gestionnaire_id"], name: "index_administrateurs_gestionnaires_on_gestionnaire_id" end + create_table "administrateurs_procedures", id: false, force: :cascade do |t| + t.bigint "administrateur_id", null: false + t.bigint "procedure_id", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["administrateur_id", "procedure_id"], name: "index_unique_admin_proc_couple", unique: true + t.index ["administrateur_id"], name: "index_administrateurs_procedures_on_administrateur_id" + t.index ["procedure_id"], name: "index_administrateurs_procedures_on_procedure_id" + end + create_table "administrations", id: :serial, force: :cascade do |t| t.string "email", default: "", null: false t.string "encrypted_password", default: "", null: false