Files
mozo-backend/app/models/product_order.rb
T
2019-01-31 10:44:06 -05:00

23 lines
639 B
Ruby

class ProductOrder
include SimplyStored::Couch
include ActiveModel::SerializerSupport
property :quantity, type: Integer
property :price, type: Float
property :product_name
property :product_variant
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.
alias_method :direct_product_name, :product_name
def product_name
direct_product_name.presence || product.try(:name) || '[deleted]'
end
end