Add uniqueness validation to Reactions

This commit is contained in:
Andreas Nedbal 2024-03-19 22:03:28 +01:00 committed by Andreas Nedbal
parent 8cdc0b28d3
commit 536d50f53d
1 changed files with 2 additions and 0 deletions

View File

@ -4,6 +4,8 @@ class Reaction < ApplicationRecord
belongs_to :parent, polymorphic: true belongs_to :parent, polymorphic: true
belongs_to :user belongs_to :user
validates_uniqueness_of :parent_id, :scope => :user_id
# rubocop:disable Rails/SkipsModelValidations # rubocop:disable Rails/SkipsModelValidations
after_create do after_create do
Notification.notify parent.user, self unless parent.user == user Notification.notify parent.user, self unless parent.user == user