Add track_id to Event

This commit is contained in:
Petko Bordjukov 2015-08-14 23:40:32 +03:00
parent 52901e976c
commit 1ea96bfdff
3 changed files with 23 additions and 2 deletions

View File

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

View File

@ -2,7 +2,7 @@ class Track < ActiveRecord::Base
include PropositionAccepting include PropositionAccepting
belongs_to :conference belongs_to :conference
has_many :events, through: :propositions, source: :proposable, source_type: Event has_many :events
validates :name, presence: true validates :name, presence: true
validates :color, presence: true, format: {with: /\A#?[a-f0-9]{6}\z/i} validates :color, presence: true, format: {with: /\A#?[a-f0-9]{6}\z/i}

View File

@ -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