title: ember: modeling a shopping cart in ember-data
body: <p>I'm struggling with getting my head around modeling a shopping cart that needs to persist to the back-end.  I think I understand the relationships, and how to retrieve data that's <em>in</em> the model...it's how to actually add the data that's tripping me up.</p>
  
  <p>I've got two pretty simple models:</p>
  
  <p>The cart:</p>
  
  <pre><code>export default DS.Model.extend({
      cartitems: hasMany('cartitem')
  });
  </code></pre>
  
  <p>The cart items</p>
  
  <pre><code>export default DS.Model.extend({
      product: belongsTo('product', { async: true }),
      cart: belongsTo('cart'),
  
      variantCodes: attr(''),
      quantity: attr('number'),
      itemPrice: attr('number'),
      itemOrigPrice: attr('number')
  
  });
  </code></pre>
  
  <p>I created a cart service that contains properties, computed properties and methods.  In this cart service is where I'm having the trouble, starting with my <code>add</code> method:</p>
  
  <pre><code>...
  
  add(item) {
      this.get('store').findRecord('cart', get(this, 'cartId')).then(result =&gt; {
          cart.get('cartitems').addObject(this.get('store').createRecord('cartitem', {
                  id: item.skuid,
                  variantCodes: item.variantCodes,
                  quantity: item.quantity,
                  itemPrice: item.itemPrice
              })
          );
          cart.save();
      });
  }
  </code></pre>
  
  <p>That kind of works...it shows the <code>cart</code> and <code>cartitem</code> models (with data and relationsips) in the ember inspector, but doesn't send a payload for the cart items to the API.  I'm thinking it's because I have to do a <code>save</code> for each <code>cartitem</code>.  </p>
  
  <p>But this rig also seems overly complex and I think would result in a bunch of network requests.  Is this even the right approach?</p>
  
  <p>I <em>think</em> the DS.EmbeddedRecordsMixin would help here, but I have no idea how that would look.  I can't seem to find any examples of it in use for POSTing to the API.  Only for retrieving.  Any help appreciated!</p>