我有一个模型“组”,它有一些hasMany关系“members”和“links”。我有一个添加新组的控制器,但我在保存
时收到以下错误App.AddGroupController = Ember.ObjectController.extend({
needs: ['application'],
actions: {
submitForm: function(){
var self = this;
var model = this.get('model');
self.send('showLoading', 'Saving');
model.save().then(function(){
self.send('hideLoading');
//Go to the groups list
self.transitionToRoute('groups');
},function(error){
self.send('hideLoading');
console.log(error);
//Must supply reject callback, otherwise Ember will throw a 'backend rejected the commit' error.
});
}
}
});
App.AddGroupRoute = App.AuthenticatedRoute.extend({
model: function(){
return this.store.createRecord('group');
}
});
App.Group = DS.Model.extend({
title: DS.attr('string'),
description: DS.attr('string'),
members: DS.hasMany('groupMember'),
links: DS.hasMany('groupLink'),
});
App.GroupLink = DS.Model.extend({
title: DS.attr('string'),
link: DS.attr('string'),
});
App.GroupMember = DS.Model.extend({
first_name: DS.attr('string'),
last_name: DS.attr('string'),
email: DS.attr('string'),
profile_picture: DS.attr('string'),
});
我可以通过在响应json中返回一个空的链接数组来解决这个问题,但我不一定要包含这个,我不明白为什么我的链接会出现这个错误而不是成员,因为它不包含在回应也是。
{
"group":{
"id":26,
"title":"Test Group",
"description":"Dummy group description",
}
}
来自保存的回复:
{{1}}
我正在使用:
恩伯:1.9.1
Ember数据:1.13.14