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.
Here's a test to reproduce it:
Looks like the problem is here
https://github.com/CodeYellowBV/backbone-relation/blob/master/index.js#L237. We set theidof the model to beundefinedeven if we do an unset.