简体   繁体   English

灰烬deleteRecord太多的递归

[英]Ember deleteRecord too much recursion

I'm having trouble getting Ember to delete a record that has a belongsTo relationship. 我无法让Ember删除具有一个Abouts关系的记录。 I have a couple models set up with a one-to-one relationship like this: 我有几个建立了一对一关系的模型,如下所示:

App.User = DS.Model.extend({
    account: DS.belongsTo('App.Account')
    ...
});

App.Account = DS.Model.extend({
    user: DS.belongsTo('App.User'),
    ...
});

This is my deleteUser method on my UserController 这是我的UserController上的deleteUser方法

deleteUser: function() {
    user = this.get('model');
    var transaction = App.store.transaction();
    transaction.add(user);
    user.deleteRecord();
    transaction.commit();
    this.transitionTo('users');
}

When it gets to user.deleteRecord(); 当到达user.deleteRecord();时 I get an error in the console Too much recursion. 我在控制台中收到错误递归过多。 Trying to step through the problem I found that infinite loop is happening in this section of code in the main ember.js file 在尝试解决该问题时,我发现在ember.js主文件的此部分代码中发生了无限循环

var meta = obj[META_KEY], desc = meta && meta.descs[keyName],
    isUnknown, currentValue;
if (desc) {
    desc.set(obj, keyName, value);
} else {
    ....
}

deleteRecord calls clearRelationships which calls Ember.set(this, "account", null) on the user object. deleteRecord调用clearRelationships,后者在用户对象上调用Ember.set(this,“ account”,null)。 Inside Ember.set() when it hits the above code it finds the reference to the user object and calls set on it.. which then finds the account and calls set on it.. which finds the user and calls set on it.. etc. 在Ember.set()内部,当按下上面的代码时,它会找到对用户对象的引用并在其上调用set ..然后,该对象会在其上找到该帐户并对其进行调用..在该帐户上会找到该用户并对其进行调用..等等

If this is a bug in Ember can anyone help me with a fix or workaround? 如果这是Ember中的错误,有人可以帮助我解决问题或解决方法吗? Here is a jsFiddle of my example 这是我的示例的jsFiddle

Looks like it was an oversight. 看来这是一个疏忽。 This pull request on github fixed the issue for me https://github.com/emberjs/data/pull/715 在github上的请求请求为我解决了这个问题https://github.com/emberjs/data/pull/715

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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