Introduce a SelectedTalk model

This commit is contained in:
Petko Bordjukov 2016-10-05 14:49:17 +03:00
parent 63a920a88b
commit 05240dfed4
5 changed files with 42 additions and 0 deletions

View File

@ -0,0 +1,3 @@
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end

View File

@ -0,0 +1,7 @@
class SelectedTalk < ApplicationRecord
belongs_to :talk_preference
def talk
Talk.find talk_id, from: :halfnarp_friendly
end
end

View File

@ -1,4 +1,6 @@
class Talk < ActiveResource::Base class Talk < ActiveResource::Base
has_many :selections, class_name: 'SelectedTalk'
self.site = "https://cfp.openfest.org/api/conferences/3" self.site = "https://cfp.openfest.org/api/conferences/3"
self.element_name = "event" self.element_name = "event"

View File

@ -1,4 +1,6 @@
class TalkPreference < ActiveRecord::Base class TalkPreference < ActiveRecord::Base
has_many :selected_talks
self.primary_key = :unique_id self.primary_key = :unique_id
serialize :talks, Array serialize :talks, Array

View File

@ -0,0 +1,28 @@
class TalkPreference < ActiveRecord::Base
self.primary_key = :unique_id
serialize :talks, Array
end
class SelectedTalk < ApplicationRecord
end
class CreateSelectedTalks < ActiveRecord::Migration[5.0]
def up
create_table :selected_talks do |t|
t.references :talk, foreign_key: false
t.string :talk_preference_id, foreign_key: true
end
talk_preferences = TalkPreference.all
talk_preferences.each do |preference|
preference.talks.each do |talk|
SelectedTalk.create! talk_id: talk, talk_preference_id: preference.unique_id
end
end
end
def down
drop_table :selected_talks
end
end