Add conference_id to Event

This commit is contained in:
Petko Bordjukov 2015-08-14 23:33:08 +03:00
parent 00a4e32939
commit 52901e976c
2 changed files with 26 additions and 1 deletions

View File

@ -2,7 +2,7 @@ class Event < ActiveRecord::Base
include Proposable include Proposable
has_one :track, through: :proposition, source: :proposition_accepting, source_type: Track has_one :track, through: :proposition, source: :proposition_accepting, source_type: Track
has_one :conference, through: :track belongs_to :conference
has_many :participations has_many :participations
has_many :pending_participations, ->() { pending }, class_name: 'Participation' has_many :pending_participations, ->() { pending }, class_name: 'Participation'

View File

@ -0,0 +1,25 @@
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
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