Create record with hasMany relationship
How can you create a record with a hasMany
relationship with Ember-Data? This is my code so far:
var project = store.createRecord('project', {
name: 'foo',
organization: organizationModel,
managers: [userModel]
});
The organization
relationship gets filled in just fine, but the managers
relationship is always empty. I've also tried using an Ember.Set()
instead of an array, same issue. I've also tried leaving the managers
property out of the hash, and doing this instead:
project.set('managers', [userModel]);
That didn't work either an array or a set. How exactly am I supposed to fill in the hasMany relationship?
If it's async
var project = store.createRecord('project', {
name: 'foo',
organization: organizationModel,
});
project.get('managers').then(function(managers){
managers.pushObject(userModel);
});
if not
var project = store.createRecord('project', {
name: 'foo',
organization: organizationModel,
});
project.get('managers').pushObject(userModel);
链接地址: http://www.djcxy.com/p/65582.html
上一篇: 在Ember Data中过滤子记录
下一篇: 用hasMany关系创建记录