clarion/db/migrate/20150814203341_add_track_id_to_events.rb

22 lines
525 B
Ruby
Raw Normal View History

2015-08-14 23:40:32 +03:00
class Event < ActiveRecord::Base
has_one :proposition, as: :proposable
end
class Proposition < ActiveRecord::Base
belongs_to :proposable, polymorphic: true
end
class AddTrackIdToEvents < ActiveRecord::Migration
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