summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorHombreLaser <sebastian-440@live.com>2023-04-04 17:37:23 -0600
committerHombreLaser <sebastian-440@live.com>2023-04-04 17:37:23 -0600
commit3afd35371caa0677fd2f66491bd337d1673013dc (patch)
treeee915480908dc2a5cac01f4b7b6ad554d78370e9 /app/models
parenta7f095d7171fe496c8037a451aaecfd234c30a01 (diff)
Añadido validador de reseña única
Diffstat (limited to 'app/models')
-rw-r--r--app/models/product_review.rb7
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