简体   繁体   English

ember.js-hasMany / belongsTo关系不会更新父模型

[英]ember.js - hasMany/belongsTo Relation doesn't update parent model

Can't fix this, but it seems to was a official bug a year ago but already closed... so maybe I'm just missing something. 无法解决此问题,但这似乎是一年前的一个正式错误,但已经关闭了……所以也许我只是想念一些东西。

I create a child but my parent model doesn't update neither at the client nor on my server. 我创建了一个子级,但我的父级模型在客户端和服务器上均未更新。

My Models: 我的模特:

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()
})

How I create my child: 我如何创建孩子:

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();
    })
}

Add the child to the parent, too: 也将孩子添加到父母中:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM