diff --git a/app/models/event.rb b/app/models/event.rb index 9034fc8..0992eac 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -1,8 +1,8 @@ class Event < ActiveRecord::Base include Proposable - has_one :track, through: :proposition, source: :proposition_accepting, source_type: Track belongs_to :conference + belongs_to :track has_many :participations has_many :pending_participations, ->() { pending }, class_name: 'Participation' diff --git a/app/models/track.rb b/app/models/track.rb index 3f4f010..a8bf6f1 100644 --- a/app/models/track.rb +++ b/app/models/track.rb @@ -2,7 +2,7 @@ class Track < ActiveRecord::Base include PropositionAccepting belongs_to :conference - has_many :events, through: :propositions, source: :proposable, source_type: Event + has_many :events validates :name, presence: true validates :color, presence: true, format: {with: /\A#?[a-f0-9]{6}\z/i} diff --git a/db/migrate/20150814203341_add_track_id_to_events.rb b/db/migrate/20150814203341_add_track_id_to_events.rb new file mode 100644 index 0000000..b47b334 --- /dev/null +++ b/db/migrate/20150814203341_add_track_id_to_events.rb @@ -0,0 +1,21 @@ +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