mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-05-18 13:38:24 -04:00
18 lines
475 B
Ruby
18 lines
475 B
Ruby
class OrderItem < ActiveRecord::Base
|
|
attr_accessible :order_id, :price, :product_id, :quantity
|
|
|
|
belongs_to :order
|
|
belongs_to :product
|
|
|
|
validate :price_must_be_greater_than_minimum
|
|
|
|
validates_uniqueness_of :order_id, :message => "may only have one item."
|
|
|
|
def price_must_be_greater_than_minimum
|
|
@product = Product.find(product_id)
|
|
if price < @product.min_price
|
|
errors.add(:price, "must be greater than the product's minimum value")
|
|
end
|
|
end
|
|
end
|