Backbone-relational icon indicating copy to clipboard operation
Backbone-relational copied to clipboard

Event relation:change is triggered when it shouldn't

Open floo51 opened this issue 11 years ago • 4 comments

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

Js fiddle to demonstration

floo51 avatar Dec 31 '13 11:12 floo51

+1

paulosborne avatar Apr 01 '14 11:04 paulosborne

Definitely an issue here.

Muon avatar Jul 11 '14 07:07 Muon

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.

dminkovsky avatar Sep 15 '14 02:09 dminkovsky

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.

floo51 avatar Sep 15 '14 12:09 floo51