Commit 43a5f214795965239b2b0a6047d18e0d94367f77

Authored by Pius Uzamere
1 parent 34e972bd

eager load item data

Showing 1 changed file with 5 additions and 2 deletions   Show diff stats
app/controllers/choices_controller.rb
... ... @@ -8,11 +8,14 @@ class ChoicesController < InheritedResources::Base
8 8 if params[:limit]
9 9 @question = Question.find(params[:question_id])#, :include => :choices)
10 10 @question.reload
11   - @choices = Choice.find(:all, :conditions => {:question_id => @question.id, :active => true}, :limit => params[:limit].to_i, :order => 'score DESC')
  11 + @choices = Choice.find(:all, :conditions => {:question_id => @question.id, :active => true}, :limit => params[:limit].to_i, :order => 'score DESC', :include => :item)
  12 +
12 13 #@choices.each {|c| c.compute_score!}
13 14 else
14 15 @question = Question.find(params[:question_id], :include => :choices) #eagerloads ALL choices
15   - @choices = @question.choices(true).active
  16 + @choices = @question.choices(true).active.find(:all, :include => :item)
  17 +
  18 +
16 19 #@choices.each {|c| c.compute_score!}
17 20 end
18 21 index! do |format|
... ...