Add Partial Results counts to question answers
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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?
|
||||
|
||||
Reference in New Issue
Block a user