2016-05-20 15:39:17 +02:00
|
|
|
class GestionnaireIsAssignToProcedure < ActiveRecord::Migration
|
2018-03-06 13:44:29 +01:00
|
|
|
class AssignTo < ApplicationRecord
|
2016-05-20 15:39:17 +02:00
|
|
|
belongs_to :gestionnaire
|
|
|
|
belongs_to :procedure
|
|
|
|
end
|
|
|
|
|
2018-03-06 13:44:29 +01:00
|
|
|
class Gestionnaire < ApplicationRecord
|
2016-05-20 15:39:17 +02:00
|
|
|
has_and_belongs_to_many :administrateurs
|
|
|
|
has_many :procedures, through: :assign_to
|
|
|
|
end
|
|
|
|
|
2018-03-06 13:44:29 +01:00
|
|
|
class Administrateur < ApplicationRecord
|
2016-05-20 15:39:17 +02:00
|
|
|
has_and_belongs_to_many :gestionnaires
|
|
|
|
has_many :procedures
|
|
|
|
end
|
|
|
|
|
2018-03-06 13:44:29 +01:00
|
|
|
class Procedure < ApplicationRecord
|
2016-05-20 15:39:17 +02:00
|
|
|
belongs_to :administrateur
|
|
|
|
has_many :gestionnaires, through: :assign_to
|
|
|
|
end
|
|
|
|
|
|
|
|
def change
|
|
|
|
create_table :assign_tos, id: false do |t|
|
|
|
|
t.belongs_to :gestionnaire, index: true
|
|
|
|
t.belongs_to :procedure, index: true
|
|
|
|
end
|
|
|
|
|
|
|
|
Administrateur.all.each do |administrateur|
|
|
|
|
administrateur.gestionnaires.each do |gestionnaire|
|
|
|
|
administrateur.procedures.each do |procedure|
|
|
|
|
AssignTo.create gestionnaire: gestionnaire, procedure: procedure
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|