mardi 30 juin 2015

Ember Data does not allow duplicate entries in hasMany relationships

I have the following model:

//order/model.coffee
Order = DS.Model.extend {
  line_items: DS.hasMany 'products', {async: true}
}

At some point I want to add the some products to the order. I found that I can only add the product once, adding the same product again does not work:

//product/route.coffee
...
actions:
    addToCart: (product)->
      order = @modelFor 'order'
      console.log order.get('line_items.length') // prints 1
      order.get('line_items').pushObject product
      console.log order.get('line_items.length') // prints 1
      ...

How can I add a model more than once to a relationship ?




Aucun commentaire:

Enregistrer un commentaire