ember.js - How to save model relationships with ember data -
i have following model:
app.loan = ds.model.extend name: ds.attr('string'), products: ds.hasmany('app.product')
then on code i'm calling save
method on loan object, has many products associated, loan gets posted server, associated objects not.
quickly looking @ code, seems intended, because calling save on record add record, , record in current transaction. associated objects added if embedded.
in case, first create new transaction, adding record , associated objects, , calling commit on transaction. like
var transaction = store.transaction(); transaction.add(loan) loan.get('products').foreach(function(product)){ transaction.add(product); }); transaction.commit()
if want embed products in loan, can configuring adapter this. assuming using default rest adapter:
ds.restadapter.map('app.loan', { products: { embedded: } }
Comments
Post a Comment