[英]ember.js - hasMany/belongsTo Relation doesn't update parent model
无法解决此问题,但这似乎是一年前的一个正式错误,但已经关闭了……所以也许我只是想念一些东西。
我创建了一个子级,但我的父级模型在客户端和服务器上均未更新。
我的模特:
var attr = DS.attr,
hasMany = DS.hasMany,
belongsTo = DS.belongsTo;
App.User = DS.Model.extend({
name: attr(),
email: attr(),
hash: attr(),
lists: hasMany('list')
})
App.List = DS.Model.extend({
user: belongsTo('user'),
name: attr(),
desc: attr(),
items: hasMany('item')
})
App.Item = DS.Model.extend({
list: belongsTo('list'),
name: attr(),
desc: attr()
})
我如何创建孩子:
addList: function(){
var list = this.store.createRecord('list', {
name: 'New list',
desc: 'Describe it here'
});
this.store.find('user', 1).then(function(user){
list.set('user', user);
list.save();
})
}
也将孩子添加到父母中:
addList: function(){
var list = this.store.createRecord('list', {
name: 'New list',
desc: 'Describe it here'
});
this.store.find('user', 1).then(function(user){
list.set('user', user);
user.get('lists').pushObject(list);
list.save();
})
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.