demarches-normaliennes/db/migrate/20160317153115_cerfa_have_user.rb

22 lines
394 B
Ruby
Raw Normal View History

class CerfaHaveUser < ActiveRecord::Migration
class Cerfa < ActiveRecord::Base
belongs_to :dossier
end
class Dossier < ActiveRecord::Base
belongs_to :user
end
class User < ActiveRecord::Base
end
def change
add_reference :cerfas, :user, references: :users
Cerfa.all.each do |cerfa|
cerfa.user_id = cerfa.dossier.user.id
cerfa.save
end
end
end