Add track_id to Event
This commit is contained in:
parent
52901e976c
commit
1ea96bfdff
|
@ -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'
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue