Skip to content

Commit

Permalink
Change where we listen to relational:unregister.
Browse files Browse the repository at this point in the history
So it doesn't depend on a model being registered (when it doesn't have an id yet), and we'll still remove existing event listeners. Ref #423.
  • Loading branch information
PaulUithol committed Jan 22, 2014
1 parent 2dc59ca commit 77c3e1e
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions backbone-relational.js
Expand Up @@ -459,7 +459,6 @@
if ( coll ) { if ( coll ) {
var modelColl = model.collection; var modelColl = model.collection;
coll.add( model ); coll.add( model );
this.listenTo( model, 'relational:unregister', this.unregister, this );
model.collection = modelColl; model.collection = modelColl;
} }
}, },
Expand Down Expand Up @@ -509,9 +508,7 @@
unregister: function( model, collection, options ) { unregister: function( model, collection, options ) {
this.stopListening( model ); this.stopListening( model );


_.each( model.getRelations(), function( rel ) { _.invoke( model.getRelations(), 'stopListening' );
rel.stopListening();
});


var coll = this.getCollection( model ); var coll = this.getCollection( model );
if ( coll.contains( model ) ) { if ( coll.contains( model ) ) {
Expand Down Expand Up @@ -1177,6 +1174,7 @@
} }


Backbone.Relational.store.processOrphanRelations(); Backbone.Relational.store.processOrphanRelations();
Backbone.Relational.store.listenTo( this, 'relational:unregister', Backbone.Relational.store.unregister );


this._queue = new Backbone.BlockingQueue(); this._queue = new Backbone.BlockingQueue();
this._queue.block(); this._queue.block();
Expand Down

0 comments on commit 77c3e1e

Please sign in to comment.