diff --git a/app/models/prompt.rb b/app/models/prompt.rb index e74f964..c9204a6 100644 --- a/app/models/prompt.rb +++ b/app/models/prompt.rb @@ -7,8 +7,8 @@ class Prompt < ActiveRecord::Base belongs_to :question, :counter_cache => true - belongs_to :left_choice, :class_name => "Choice", :foreign_key => "left_choice_id", :counter_cache => true - belongs_to :right_choice, :class_name => "Choice", :foreign_key => "right_choice_id", :counter_cache => true + belongs_to :left_choice, :class_name => "Choice", :foreign_key => "left_choice_id", :counter_cache => :prompts_on_the_left_count + belongs_to :right_choice, :class_name => "Choice", :foreign_key => "right_choice_id", :counter_cache => :prompts_on_the_right_count validates_presence_of :left_choice, :on => :create, :message => "can't be blank" validates_presence_of :right_choice, :on => :create, :message => "can't be blank" diff --git a/lib/tasks/test_api.rake b/lib/tasks/test_api.rake index 2c5c265..013899a 100644 --- a/lib/tasks/test_api.rake +++ b/lib/tasks/test_api.rake @@ -1,6 +1,6 @@ namespace :test_api do - desc "Updates cached values for losses and wins for for choices." + desc "Updates cached values for losses and wins for choices." task :update_cached_losses_wins => :environment do Question.all.each do |question| question.choices.each do |choice| @@ -17,6 +17,20 @@ namespace :test_api do end end + desc "Update cached values for prompts on left and right for choices." + task :update_cahced_prompts_on_left_right => :environment do + Question.all.each do |question| + question.choices.each do |choice| + choice.reload + choice.prompts_on_the_left + choice.prompts_on_the_right + Choice.update_counters choice.id, + :prompts_on_the_left_count => choice.prompts_on_the_left.count, + :prompts_on_the_right_count => choice.prompts_on_the_right.count + end + end + end + desc "Recomputes scores for all choices." task :recompute_scores => :environment do Choice.find_each do |choice| -- libgit2 0.21.2