19 lines
460 B
Ruby
19 lines
460 B
Ruby
class ProductOrder
|
|
include SimplyStored::Couch
|
|
|
|
property :amount, type: Fixnum
|
|
property :price, type: Float
|
|
|
|
belongs_to :product
|
|
belongs_to :order
|
|
|
|
view :by_product_id, key: :product_id
|
|
view :by_order_id, key: :order_id
|
|
|
|
# Getter for product name. If a supplier deletes a product, that has product_orders, the product
|
|
# will become nil. This method should handle this case.
|
|
def product_name
|
|
product.try(:name) || '[deleted]'
|
|
end
|
|
end
|