diff --git a/app/models/talk_preference.rb b/app/models/talk_preference.rb index 330fb1e..fc5a2d3 100644 --- a/app/models/talk_preference.rb +++ b/app/models/talk_preference.rb @@ -3,8 +3,6 @@ class TalkPreference < ActiveRecord::Base self.primary_key = :unique_id - serialize :talks, Array - before_create :assign_new_unique_id def include?(id) @@ -20,6 +18,10 @@ class TalkPreference < ActiveRecord::Base where created_at: timespan end + def talks + selected_talks.pluck :talk_id + end + private def assign_new_unique_id diff --git a/db/migrate/20161005115007_remove_talks_from_talk_preferences.rb b/db/migrate/20161005115007_remove_talks_from_talk_preferences.rb new file mode 100644 index 0000000..b144427 --- /dev/null +++ b/db/migrate/20161005115007_remove_talks_from_talk_preferences.rb @@ -0,0 +1,26 @@ +class TalkPreference < ActiveRecord::Base + self.primary_key = :unique_id + has_many :selected_talks + serialize :talks, Array +end + +class SelectedTalk < ApplicationRecord + belongs_to :talk_preference +end + +class RemoveTalksFromTalkPreferences < ActiveRecord::Migration[5.0] + def up + remove_column :talk_preferences, :talks, :text + end + + def down + add_column :talk_preferences, :talks, :text + + talk_preferences = TalkPreference.all + + talk_preferences.each do |preference| + preference.talks = preference.selected_talks.pluck(:talk_id) + preference.save! + end + end +end