From 649c5a768cf81254fc5558ef33a0eb6e843d94f3 Mon Sep 17 00:00:00 2001 From: Petko Bordjukov Date: Mon, 13 Oct 2014 16:50:16 +0300 Subject: [PATCH] Allow an event to have more than one speaker --- app/models/event.rb | 1 + ...013134153_create_events_to_speakers_join_table.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 db/migrate/20141013134153_create_events_to_speakers_join_table.rb diff --git a/app/models/event.rb b/app/models/event.rb index 4776123..426c4f5 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -10,6 +10,7 @@ class Event < ActiveRecord::Base has_one :conference, through: :track belongs_to :user # XXX: Transition to candidate_speaker belongs_to :candidate_speaker, class_name: 'User', foreign_key: 'user_id' + has_and_belongs_to_many :speakers, class_name: 'SpeakerProfile' after_create :send_new_event_notification diff --git a/db/migrate/20141013134153_create_events_to_speakers_join_table.rb b/db/migrate/20141013134153_create_events_to_speakers_join_table.rb new file mode 100644 index 0000000..a2354c4 --- /dev/null +++ b/db/migrate/20141013134153_create_events_to_speakers_join_table.rb @@ -0,0 +1,12 @@ +class CreateEventsToSpeakersJoinTable < ActiveRecord::Migration + def up + create_join_table :events, :speaker_profiles + Event.all.each do |event| + event.speakers << event.user.speaker_profile if event.user.speaker_profile.present? + end + end + + def down + drop_table :events_speaker_profiles + end +end