如何创建与Ember-Data有hasMany
关系的记录?到目前为止,这是我的代码:
var project = store.createRecord('project', {
name: 'foo',
organization: organizationModel,
managers: [userModel]
});
organization
关系可以很好地填充,但managers
关系始终为空。我也尝试使用Ember.Set()
而不是数组,同样的问题。我也尝试将managers
属性从哈希中删除,而是这样做:
project.set('managers', [userModel]);
这不适用于数组或集合。我到底应该如何填写hasMany关系?
答案 0 :(得分:2)
如果它是异步
var project = store.createRecord('project', {
name: 'foo',
organization: organizationModel,
});
project.get('managers').then(function(managers){
managers.pushObject(userModel);
});
如果不是
var project = store.createRecord('project', {
name: 'foo',
organization: organizationModel,
});
project.get('managers').pushObject(userModel);