# frozen_string_literal: true # ProductReview # review: text # rating: integer class ProductReview < ApplicationRecord belongs_to :user_account belongs_to :product 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