问题
I have classic multimodel form: a transport document that has many transport_document_rows, as stated in my MODELS:
App.TransportDocument = DS.Model.extend
number: DS.attr 'string'
date: DS.attr 'string'
transportDocumentRows: DS.hasMany('App.TransportDocumentRow')
App.TransportDocumentRow = DS.Model.extend
productName: DS.attr 'string'
quantity: DS.attr 'string'
transportDocument: DS.belongsTo('App.TransportDocument')
I write in console this script:
a = App.Invoice.createRecord();
a.get("invoiceRows").pushObject(App.InvoiceRow.createRecord());
a.get("store").commit();
And the problem is the following:
- My transport document is created correctly
- My transport document row is created SEQUENTLY (and it could still be not a problem) but with a wrong transport_document_id (transport_document_id: 0).
Is this behaviour expected? What could I do to correct it?
Thanks
EDIT: the only way it works is using the embedded option:
DS.RESTAdapter.map 'App.TransportDocument', {
transportDocumentRows: { embedded: 'always' }
}
This options commits the transport document and its rows in a single HTTP request.
This requires changing the GET response, including the transport_document_rows
content direcly in the transport_documents
key of the response hash
来源:https://stackoverflow.com/questions/16466327/ember-js-multimodel-forms-what-is-expected-from-ember-data