poll_answers = PollAnswer.joins(:poll_answer_variant => {:poll_question => :poll}).select("count(poll_answers.user_id) as submits_count, poll_answers.poll_question_id").where("polls.id = 105").group("poll_questions.id, poll_answer_variants.id")
grouped = poll_answers.group_by(&:poll_question_id)
grouped[81].inject{|sum, answer_variant| sum += answer_variant.submits_count}
私が得たものの後:
NoMethodError: undefined method `+' for #<PollAnswer poll_question_id: 81, poll_answer_variant_id: 9>
from /Users/s/.rvm/gems/ruby-1.9.3-p194/gems/activemodel-3.2.7/lib/active_model/attribute_methods.rb:407:in `method_missing'
from /Users/s/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.7/lib/active_record/attribute_methods.rb:149:in `method_missing'
from (irb):926:in `block in irb_binding'
from (irb):926:in `each'
from (irb):926:in `inject'
from (irb):926
from /Users/s/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.7/lib/rails/commands/console.rb:47:in `start'
from /Users/s/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.7/lib/rails/commands/console.rb:8:in `start'
from /Users/s/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.7/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
これは、仮想選択カウントがモデル属性のように記述されていないためである必要がありますか?どうすれば修正できますか?どうも