demarches-normaliennes/db/migrate/20160317144949_piece_justificative_have_user.rb

22 lines
501 B
Ruby
Raw Normal View History

class PieceJustificativeHaveUser < ActiveRecord::Migration
2018-03-06 13:44:29 +01:00
class PieceJustificative < ApplicationRecord
belongs_to :dossier
end
2018-03-06 13:44:29 +01:00
class Dossier < ApplicationRecord
belongs_to :user
end
2018-03-06 13:44:29 +01:00
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