diff options
author | HombreLaser <sebastian-440@live.com> | 2023-04-04 17:37:23 -0600 |
---|---|---|
committer | HombreLaser <sebastian-440@live.com> | 2023-04-04 17:37:23 -0600 |
commit | 3afd35371caa0677fd2f66491bd337d1673013dc (patch) | |
tree | ee915480908dc2a5cac01f4b7b6ad554d78370e9 /app/models | |
parent | a7f095d7171fe496c8037a451aaecfd234c30a01 (diff) |
Añadido validador de reseña única
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/product_review.rb | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/app/models/product_review.rb b/app/models/product_review.rb index ceade9a..0985e7c 100644 --- a/app/models/product_review.rb +++ b/app/models/product_review.rb @@ -9,4 +9,11 @@ class ProductReview < ApplicationRecord validates :review, presence: true validates :rating, presence: true, inclusion: { in: 1..5 } + validate :sole_user_review + + def sole_user_review + return if ProductReview.find_by(user_account_id:, product_id:).nil? + + errors.add(:review, 'User has already published a review') + end end |