diff --git a/app/models/event.rb b/app/models/event.rb index 3206c86..9034fc8 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -2,7 +2,7 @@ class Event < ActiveRecord::Base include Proposable has_one :track, through: :proposition, source: :proposition_accepting, source_type: Track - has_one :conference, through: :track + belongs_to :conference has_many :participations has_many :pending_participations, ->() { pending }, class_name: 'Participation' diff --git a/db/migrate/20150814202053_add_conference_id_to_events.rb b/db/migrate/20150814202053_add_conference_id_to_events.rb new file mode 100644 index 0000000..fa2d097 --- /dev/null +++ b/db/migrate/20150814202053_add_conference_id_to_events.rb @@ -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