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

22 lines
391 B
Ruby
Raw Normal View History

class CerfaHaveUser < ActiveRecord::Migration
2018-03-06 13:44:29 +01:00
class Cerfa < 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 :cerfas, :user, references: :users
Cerfa.all.each do |cerfa|
cerfa.user_id = cerfa.dossier.user.id
cerfa.save
end
end
end