clarion/db/migrate/20150814203341_add_track_id...

22 lines
530 B
Ruby

class Event < ActiveRecord::Base
has_one :proposition, as: :proposable
end
class Proposition < ActiveRecord::Base
belongs_to :proposable, polymorphic: true
end
class AddTrackIdToEvents < ActiveRecord::Migration[4.2]
def up
add_reference :events, :track, index: true, foreign_key: true
Event.all.includes(:proposition).each do |event|
event.update!(track_id: event.proposition.proposition_accepting_id)
end
end
def down
remove_reference :events, :track, index: true, foreign_key: true
end
end