我正在努力实现这一目标 部门-HasMany->联系人。
没有任何线索部门得到保存但联系人没有得到保存
您可以在jsbin
中参考此部分App.NewcontactController = Ember.ObjectController.extend({
needs: ['department'],
save: function () {
var department = this.get('controllers.department').get('model');
var newContact = App.Contact.create({
name: this.get('name'),
department: department
});
department.get('contacts').addObject(newContact);
console.log(department);
console.log(newContact);
department.get('contacts').save();
department.save();
console.log('---saved contact---');
this.transitionTo('contact',newContact);
}
});
Firebug LocalStorage
Contact-1 "{"id":"1","department_id":"1"}"
Department-1 "{"id":"1","name":"A","contact_ids":[]}" //NO ids :(
已更新 Ember模型与Ember-Model-LocalStorage
答案 0 :(得分:0)
保存父级不会保存子级。您有责任自己拯救孩子。在hasMany关系上有一个save
方法可以让它更容易一些。