Permalink
Browse files

Change where we listen to `relational:unregister`.

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...
1 parent 2dc59ca commit 77c3e1e1e888d7fdac523daf8a796f198582401c @PaulUithol committed Jan 22, 2014
Showing with 2 additions and 4 deletions.
  1. +2 −4 backbone-relational.js
@@ -459,7 +459,6 @@
if ( coll ) {
var modelColl = model.collection;
coll.add( model );
- this.listenTo( model, 'relational:unregister', this.unregister, this );
model.collection = modelColl;
}
},
@@ -509,9 +508,7 @@
unregister: function( model, collection, options ) {
this.stopListening( model );
- _.each( model.getRelations(), function( rel ) {
- rel.stopListening();
- });
+ _.invoke( model.getRelations(), 'stopListening' );
var coll = this.getCollection( model );
if ( coll.contains( model ) ) {
@@ -1177,6 +1174,7 @@
}
Backbone.Relational.store.processOrphanRelations();
+ Backbone.Relational.store.listenTo( this, 'relational:unregister', Backbone.Relational.store.unregister );
this._queue = new Backbone.BlockingQueue();
this._queue.block();

0 comments on commit 77c3e1e

Please sign in to comment.