clarion/db/migrate/20150814202053_add_conference_id_to_events.rb
2019-04-28 11:56:16 +03:00

26 lines
654 B
Ruby

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