36 lines
982 B
Ruby
36 lines
982 B
Ruby
class GestionnaireIsAssignToProcedure < ActiveRecord::Migration
|
|
class AssignTo < ActiveRecord::Base
|
|
belongs_to :gestionnaire
|
|
belongs_to :procedure
|
|
end
|
|
|
|
class Gestionnaire < ActiveRecord::Base
|
|
has_and_belongs_to_many :administrateurs
|
|
has_many :procedures, through: :assign_to
|
|
end
|
|
|
|
class Administrateur < ActiveRecord::Base
|
|
has_and_belongs_to_many :gestionnaires
|
|
has_many :procedures
|
|
end
|
|
|
|
class Procedure < ActiveRecord::Base
|
|
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
|