Files
mozo-backend/app/assets/javascripts/user/app/models/order.js.coffee
T
2014-03-31 15:51:01 +02:00

13 lines
500 B
CoffeeScript

attr = DS.attr
App.Order = DS.Model.extend
state: attr 'string'
list: DS.belongsTo('list')
table: DS.belongsTo('table')
product_orders: DS.hasMany('product_order', embedded: 'always')
total: (->
@get('product_orders').getEach('total').reduce(((sum, total) -> sum + total), 0)
).property('product_orders.@each.quantity')
display: (->
@get('product_orders').map((po) -> "#{po.get('quantity')} x #{po.get('product.name')}").join(', ')
).property('product_orders.@each.quantity')