Permalink
Browse files

Add `Backbone.Store.removeModelScope` method. Ref #281

  • Loading branch information...
1 parent 7a2984e commit 43cb2d6f3ec4b18db597e59b4e9c5004d77447fa @PaulUithol committed Mar 12, 2013
Showing with 28 additions and 1 deletion.
  1. +9 −1 backbone-relational.js
  2. +19 −0 test/tests.js
@@ -150,6 +150,14 @@
},
/**
+ * Remove a scope.
+ * @param {Object} scope
+ */
+ removeModelScope: function( scope ) {
+ this._modelScopes = _.without( this._modelScopes, scope );
+ },
+
+ /**
* Add a set of subModelTypes to the store, that can be used to resolve the '_superModel'
* for a model later in 'setupSuperModel'.
*
@@ -1414,7 +1422,7 @@
value = related.get( includeInJSON );
}
- // Add 'unfound' ids if only includeInJSON is the `idAttribute`
+ // Add ids for 'unfound' models if includeInJSON is equal to (only) the relatedModel's `idAttribute`
if ( includeInJSON === rel.relatedModel.prototype.idAttribute ) {
if ( rel instanceof Backbone.HasMany ) {
value = value.concat( rel.keyIds );
View
@@ -630,6 +630,25 @@ $(document).ready(function() {
ok( people.at(0).iam() == "I am a student" );
});
+ test( "removeModelScope", function() {
+ var models = {};
+ Backbone.Relational.store.addModelScope( models );
+
+ models.Page = Backbone.RelationalModel.extend();
+
+ ok( Backbone.Relational.store.getObjectByName( 'Page' ) === models.Page );
+ ok( Backbone.Relational.store.getObjectByName( 'Person' ) === window.Person );
+
+ Backbone.Relational.store.removeModelScope( models );
+
+ ok( !Backbone.Relational.store.getObjectByName( 'Page' ) );
+ ok( Backbone.Relational.store.getObjectByName( 'Person' ) === window.Person );
+
+ Backbone.Relational.store.removeModelScope( window );
+
+ ok( !Backbone.Relational.store.getObjectByName( 'Person' ) );
+ });
+
test( "`eventQueue` is unblocked again after a duplicate id error", 3, function() {
var node = new Node( { id: 1 } );

0 comments on commit 43cb2d6

Please sign in to comment.