diff --git a/app/models/poll/answer.rb b/app/models/poll/answer.rb index 1e602086b..de8daffb1 100644 --- a/app/models/poll/answer.rb +++ b/app/models/poll/answer.rb @@ -9,9 +9,7 @@ class Poll::Answer < ApplicationRecord validates :author, presence: true validates :answer, presence: true - validates :answer, inclusion: { in: ->(a) { a.question.question_answers - .joins(:translations) - .pluck("poll_question_answer_translations.title") }}, + validates :answer, inclusion: { in: ->(a) { a.question.possible_answers }}, unless: ->(a) { a.question.blank? } scope :by_author, ->(author_id) { where(author_id: author_id) } diff --git a/app/models/poll/partial_result.rb b/app/models/poll/partial_result.rb index 23821bd60..4c29144dd 100644 --- a/app/models/poll/partial_result.rb +++ b/app/models/poll/partial_result.rb @@ -10,10 +10,7 @@ class Poll::PartialResult < ApplicationRecord validates :question, presence: true validates :author, presence: true validates :answer, presence: true - validates :answer, inclusion: { in: ->(a) { a.question.question_answers - .visibles - .joins(:translations) - .pluck("poll_question_answer_translations.title") }}, + validates :answer, inclusion: { in: -> (a) { a.question.possible_answers }}, unless: ->(a) { a.question.blank? } validates :origin, inclusion: { in: VALID_ORIGINS } diff --git a/app/models/poll/question.rb b/app/models/poll/question.rb index bd8d8e79b..4daf38f76 100644 --- a/app/models/poll/question.rb +++ b/app/models/poll/question.rb @@ -87,4 +87,8 @@ class Poll::Question < ApplicationRecord def is_positive_negative? votation_type.present? && enum_type == "positive_negative_open" end + + def possible_answers + question_answers.visibles.joins(:translations).pluck("poll_question_answer_translations.title") + end end