Validate uniqueness of answers for questions

This commit is contained in:
Andreas Nedbal 2023-01-01 21:20:58 +01:00 committed by Andreas Nedbal
parent 0d34037dc7
commit 7b0a615193
1 changed files with 2 additions and 0 deletions

View File

@ -8,6 +8,8 @@ class Answer < ApplicationRecord
has_many :subscriptions, dependent: :destroy
has_many :comment_smiles, through: :comments, source: :smiles
validates :question_id, uniqueness: { scope: :user_id }
# rubocop:disable Rails/SkipsModelValidations
after_create do
Inbox.where(user: self.user, question: self.question).destroy_all