Backbone-relational
Backbone-relational copied to clipboard
Event relation:change is triggered when it shouldn't
When setting nest model values to same current values, relation:change event is triggered. And unless i'm mistaken, it shouldn't.
It seems pretty similar to #140.
Code example
var Phone = Backbone.RelationalModel.extend();
var Contact = Backbone.RelationalModel.extend({
relations: [
{
type: Backbone.HasMany,
key: 'phones',
relatedModel: Phone,
reverseRelation: {
key: 'contact'
}
}
]
});
var contactData = {
"id": "contact-2",
"phones": []
};
var contact = new Contact(contactData);
contact.on('change', function() {
console.log( 'contact:change');
});
contact.on('all', function(evt) {
console.log( 'contact:' + evt );
});
contact.set(contactData);
+1
Definitely an issue here.
Doesn't seem to be an issue anymore. Check out the fiddle. Only the internal relational
event is fired, which happens when you set a relational key. But the public change
does not get fired.
The public change does not get fired either when it should then. http://jsfiddle.net/floo51/2xumV/5/
It doesn't make sense, either the event is not internal and is always triggered as stated in the original issue description or it is internal and then some event definitely lacks on the first end of the relation.