From f4260788eb808ea14ed12017452811c85ebdc8f1 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Mon, 23 Oct 2017 23:51:55 +0200 Subject: [PATCH] Add Partial Results counts to question answers --- app/models/poll/question.rb | 2 +- app/models/poll/question/answer.rb | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/models/poll/question.rb b/app/models/poll/question.rb index 22a63168a..6ec328864 100644 --- a/app/models/poll/question.rb +++ b/app/models/poll/question.rb @@ -59,7 +59,7 @@ class Poll::Question < ApplicationRecord end def answers_total_votes - question_answers.map { |a| Poll::Answer.where(question_id: self, answer: a.title).count }.sum + question_answers.inject(0) { |total, question_answer| total + question_answer.total_votes } end end diff --git a/app/models/poll/question/answer.rb b/app/models/poll/question/answer.rb index b2434aa3b..fa6ba013d 100644 --- a/app/models/poll/question/answer.rb +++ b/app/models/poll/question/answer.rb @@ -32,7 +32,8 @@ class Poll::Question::Answer < ApplicationRecord end def total_votes - Poll::Answer.where(question_id: question, answer: title).count + Poll::Answer.where(question_id: question, answer: title).count + + ::Poll::PartialResult.where(question: question).where(answer: title).sum(:amount) end def most_voted?