Permalink
Browse files

Allowing collections to remove models by either Cid or Id (prefering …

…cid).
  • Loading branch information...
1 parent 11dcf24 commit 52c460bc12d2127f1c76d6052b71f7f272acbc82 @samuelclay samuelclay committed Nov 17, 2010
Showing with 25 additions and 1 deletion.
  1. +1 −1 backbone.js
  2. +24 −0 test/collection.js
View
2 backbone.js
@@ -536,7 +536,7 @@
// hash indexes for `id` and `cid` lookups.
_remove : function(model, options) {
options || (options = {});
- model = this.getByCid(model);
+ model = this.getByCid(model) || this.get(model);
if (!model) return null;
delete this._byId[model.id];
delete this._byCid[model.cid];
View
24 test/collection.js
@@ -70,6 +70,30 @@ $(document).ready(function() {
equals(col.length, 4);
equals(col.first(), d);
});
+
+ test("Collection: remove in multiple collections", function() {
+ var modelData = {
+ id : 5,
+ title : 'Othello'
+ };
+ var passed = false;
+ var e = new Backbone.Model(modelData);
+ var f = new Backbone.Model(modelData);
+ f.bind('remove', function() {
+ passed = true;
+ });
+ var colE = new Backbone.Collection([e]);
+ var colF = new Backbone.Collection([f]);
+ ok(e != f);
+ ok(colE.length == 1);
+ ok(colF.length == 1);
+ colE.remove(e);
+ equals(passed, false);
+ ok(colE.length == 0);
+ colF.remove(e);
+ ok(colF.length == 0);
+ equals(passed, true);
+ });
test("Collection: fetch", function() {
col.fetch();

0 comments on commit 52c460b

Please sign in to comment.