summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
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