Count total_votes by option_id instead of answer title

This makes Option#total_votes independent of translations
and resilient to title changes.
This commit is contained in:
taitus
2025-09-04 16:29:08 +02:00
parent 3b827e3e95
commit 3a9f761476
3 changed files with 120 additions and 2 deletions

View File

@@ -40,8 +40,7 @@ class Poll::Question::Option < ApplicationRecord
end
def total_votes
Poll::Answer.where(question_id: question, answer: title).count +
::Poll::PartialResult.where(question: question).where(answer: title).sum(:amount)
answers.count + partial_results.sum(:amount)
end
def total_votes_percentage