demarches-normaliennes/db/migrate/20160317144949_piece_justificative_have_user.rb
2018-03-06 17:18:44 +01:00

21 lines
501 B
Ruby

class PieceJustificativeHaveUser < ActiveRecord::Migration
class PieceJustificative < ApplicationRecord
belongs_to :dossier
end
class Dossier < ApplicationRecord
belongs_to :user
end
class User < ApplicationRecord
end
def change
add_reference :pieces_justificatives, :user, references: :users
PieceJustificative.all.each do |piece_justificative|
piece_justificative.user_id = piece_justificative.dossier.user.id
piece_justificative.save
end
end
end