简体   繁体   中英

Ember deleteRecord too much recursion

I'm having trouble getting Ember to delete a record that has a belongsTo relationship. 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

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

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. 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.

If this is a bug in Ember can anyone help me with a fix or workaround? Here is a jsFiddle of my example

Looks like it was an oversight. This pull request on github fixed the issue for me https://github.com/emberjs/data/pull/715

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