mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-03-24 17:54:59 -04:00
13 lines
397 B
Ruby
13 lines
397 B
Ruby
class OrderItem < ApplicationRecord
|
|
belongs_to :order
|
|
belongs_to :product
|
|
|
|
validate :price_must_be_greater_than_minimum
|
|
validates :order_id, uniqueness: { message: "may only have one item." }
|
|
|
|
def price_must_be_greater_than_minimum
|
|
@product = Product.find(product_id)
|
|
errors.add(:price, "must be greater than the product's minimum value") if price < @product.min_price
|
|
end
|
|
end
|