干杯! 例如我有三个模型:
App.Foo = DS.Model.extend({
bars: DS.hasMany('App.Bar', {embedded:'always'}),
bazes: DS.hasMany('App.Baz', {embedded:'always'})
});
App.Bar = DS.Model.extend({
foo: DS.belongsTo('App.Foo')
});
App.Baz = DS.Model.extend({
foo: DS.belongsTo('App.Foo)
});
以及像这样的适配器映射:
App.RESTSerializer = DS.RESTSerializer.extend({
init: function() {
this._super();
this.map('App.Foo', {
bars:{embedded: 'always'},
bazes:{embedded: 'always'}
})
}
});
我首先在单独的事务中保存子记录(github.com/emberjs/data/pull/440):
barTransaction = App.store.transaction();
bar = barTransaction.createRecord(App.Bar);
//later
bazTransaction = App.store.transaction();
baz = bazTransaction.createRecord(App.Baz);
//later
fooTransaction = App.store.transaction();
foo = fooTransaction.createRecord(App.Foo);
//later
foo.get('bars').addObject(bar);
foo.get('bazes').addObject(baz);
fooTransaction.commit();
我只想知道是否可以通过一个 POST 请求保存父记录和所有子记录?现在它为每个子记录分别创建一个 POST 请求。