Commit a511fe4bce2841753b3d3a7f5077516fc23b27b8
1 parent
5d15fae2
Exists in
master
and in
1 other branch
get choice prompts_on_the_left/right counter caches working
Showing
2 changed files
with
17 additions
and
3 deletions
Show diff stats
app/models/prompt.rb
@@ -7,8 +7,8 @@ class Prompt < ActiveRecord::Base | @@ -7,8 +7,8 @@ class Prompt < ActiveRecord::Base | ||
7 | 7 | ||
8 | 8 | ||
9 | belongs_to :question, :counter_cache => true | 9 | belongs_to :question, :counter_cache => true |
10 | - belongs_to :left_choice, :class_name => "Choice", :foreign_key => "left_choice_id", :counter_cache => true | ||
11 | - belongs_to :right_choice, :class_name => "Choice", :foreign_key => "right_choice_id", :counter_cache => true | 10 | + belongs_to :left_choice, :class_name => "Choice", :foreign_key => "left_choice_id", :counter_cache => :prompts_on_the_left_count |
11 | + belongs_to :right_choice, :class_name => "Choice", :foreign_key => "right_choice_id", :counter_cache => :prompts_on_the_right_count | ||
12 | 12 | ||
13 | validates_presence_of :left_choice, :on => :create, :message => "can't be blank" | 13 | validates_presence_of :left_choice, :on => :create, :message => "can't be blank" |
14 | validates_presence_of :right_choice, :on => :create, :message => "can't be blank" | 14 | validates_presence_of :right_choice, :on => :create, :message => "can't be blank" |
lib/tasks/test_api.rake
1 | namespace :test_api do | 1 | namespace :test_api do |
2 | 2 | ||
3 | - desc "Updates cached values for losses and wins for for choices." | 3 | + desc "Updates cached values for losses and wins for choices." |
4 | task :update_cached_losses_wins => :environment do | 4 | task :update_cached_losses_wins => :environment do |
5 | Question.all.each do |question| | 5 | Question.all.each do |question| |
6 | question.choices.each do |choice| | 6 | question.choices.each do |choice| |
@@ -17,6 +17,20 @@ namespace :test_api do | @@ -17,6 +17,20 @@ namespace :test_api do | ||
17 | end | 17 | end |
18 | end | 18 | end |
19 | 19 | ||
20 | + desc "Update cached values for prompts on left and right for choices." | ||
21 | + task :update_cahced_prompts_on_left_right => :environment do | ||
22 | + Question.all.each do |question| | ||
23 | + question.choices.each do |choice| | ||
24 | + choice.reload | ||
25 | + choice.prompts_on_the_left | ||
26 | + choice.prompts_on_the_right | ||
27 | + Choice.update_counters choice.id, | ||
28 | + :prompts_on_the_left_count => choice.prompts_on_the_left.count, | ||
29 | + :prompts_on_the_right_count => choice.prompts_on_the_right.count | ||
30 | + end | ||
31 | + end | ||
32 | + end | ||
33 | + | ||
20 | desc "Recomputes scores for all choices." | 34 | desc "Recomputes scores for all choices." |
21 | task :recompute_scores => :environment do | 35 | task :recompute_scores => :environment do |
22 | Choice.find_each do |choice| | 36 | Choice.find_each do |choice| |