Add option_id to partial results and unique index

Similar to what we did in PR "Avoid duplicate records in poll answers" 5539,
specifically in commit 503369166, we want to stop relying on the plain text
"answer" and start using "option_id" to avoid issues with counts across
translations and to add consistency to the poll_partial_results table.

Note that we also moved the `possible_answers` method from Poll::Question to
Poll::Question::Option, since the list of valid answers really comes from the
options of a question and not from the question itself. Tests were updated
to validate answers against the translations of the assigned option.

Additionally, we renamed lambda parameters in validations to improve clarity.
This commit is contained in:
taitus
2025-09-10 12:22:08 +02:00
parent f2153f2b4d
commit a29eeaf2e2
13 changed files with 137 additions and 51 deletions

View File

@@ -49,10 +49,6 @@ class Poll::Question < ApplicationRecord
question_options.max_by(&:total_votes)&.id
end
def possible_answers
question_options.joins(:translations).pluck(:title)
end
def options_with_read_more?
options_with_read_more.any?
end