diff --git a/app/models/application_record.rb b/app/models/application_record.rb new file mode 100644 index 0000000..10a4cba --- /dev/null +++ b/app/models/application_record.rb @@ -0,0 +1,3 @@ +class ApplicationRecord < ActiveRecord::Base + self.abstract_class = true +end diff --git a/app/models/selected_talk.rb b/app/models/selected_talk.rb new file mode 100644 index 0000000..20c92b1 --- /dev/null +++ b/app/models/selected_talk.rb @@ -0,0 +1,7 @@ +class SelectedTalk < ApplicationRecord + belongs_to :talk_preference + + def talk + Talk.find talk_id, from: :halfnarp_friendly + end +end diff --git a/app/models/talk.rb b/app/models/talk.rb index b219d79..85c222d 100644 --- a/app/models/talk.rb +++ b/app/models/talk.rb @@ -1,4 +1,6 @@ class Talk < ActiveResource::Base + has_many :selections, class_name: 'SelectedTalk' + self.site = "https://cfp.openfest.org/api/conferences/3" self.element_name = "event" diff --git a/app/models/talk_preference.rb b/app/models/talk_preference.rb index 957d595..330fb1e 100644 --- a/app/models/talk_preference.rb +++ b/app/models/talk_preference.rb @@ -1,4 +1,6 @@ class TalkPreference < ActiveRecord::Base + has_many :selected_talks + self.primary_key = :unique_id serialize :talks, Array diff --git a/db/migrate/20161005112915_create_selected_talks.rb b/db/migrate/20161005112915_create_selected_talks.rb new file mode 100644 index 0000000..de9d2e5 --- /dev/null +++ b/db/migrate/20161005112915_create_selected_talks.rb @@ -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