From ed282a9882f1b84e5f3b697c8b227f96e60a0f43 Mon Sep 17 00:00:00 2001 From: Saimon Moore Date: Wed, 30 Nov 2011 18:54:00 +0100 Subject: [PATCH] When resetting the subset, repopulate with filtered models from the parent. All models in the subset should be the same instance as in the parent collection. Corrected test to reflect this. --- backbone.subset.js | 6 ++++-- test/test.js | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/backbone.subset.js b/backbone.subset.js index 581382b..80727ef 100644 --- a/backbone.subset.js +++ b/backbone.subset.js @@ -74,8 +74,10 @@ this.each(this._unbindModelEvents); this._reset(); - _.each(models, function (model) { - this._addToSubset(model, {silent: true}); + this.parent().each(function (model) { + if (this.sieve(model)) { + this._addToSubset(model, {silent: true}); + } }, this); if (!options.silent) { diff --git a/test/test.js b/test/test.js index 22821e6..2141cb9 100644 --- a/test/test.js +++ b/test/test.js @@ -190,6 +190,6 @@ describe('Aggregated collections', function () { assert.deepEqual(tasks.pluck('id'), [0, 4, 5]); assert.deepEqual(archived_tasks.pluck('id'), [5]); assert.deepEqual(_.pluck(tasks.models, 'cid'), ['c6', 'c8', 'c9']); - assert.deepEqual(_.pluck(archived_tasks.models, 'cid'), ['c11']); + assert.deepEqual(_.pluck(archived_tasks.models, 'cid'), ['c9']); }); });