Add Partial Results counts to question answers

This commit is contained in:
Bertocq
2017-10-23 23:51:55 +02:00
committed by Javi Martín
parent ba9346162c
commit f4260788eb
2 changed files with 3 additions and 2 deletions

View File

@@ -59,7 +59,7 @@ class Poll::Question < ApplicationRecord
end end
def answers_total_votes 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
end end

View File

@@ -32,7 +32,8 @@ class Poll::Question::Answer < ApplicationRecord
end end
def total_votes 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 end
def most_voted? def most_voted?