简体   繁体   中英

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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