Skip to content

.unset() is not working as expected #1

@mdamien

Description

@mdamien

Here's a test to reproduce it:

class Pony extends Model {
    relations() {
        return {
            favorite_food: Backbone.Model,
        };
    }
}

var me = new Pony();
var lasagna = new Backbone.Model({id: 42, name: 'Spinach Lasagna'});
me.set('favorite_food', lasagna);
me.unset('favorite_food');
console.log(me.get('favorite_food').toJSON()); // => {id: 42, name: 'Spinach Lasagna'} instead of undefined

Looks like the problem is here https://github.com/CodeYellowBV/backbone-relation/blob/master/index.js#L237. We set the id of the model to be undefined even if we do an unset.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions