ember.js multimodel forms: what is expected from ember-data?

徘徊边缘 提交于 2019-12-13 06:13:48

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!