From 973c96268f03c193d6f37d473a22cd31da4ad381 Mon Sep 17 00:00:00 2001 From: Fabien Franzen Date: Thu, 24 Jul 2014 15:55:00 +0200 Subject: [PATCH] Fix scoped destroyAll: only use 'where', not full 'filter' args --- lib/scope.js | 3 ++- test/relations.test.js | 29 ++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/lib/scope.js b/lib/scope.js index 51c97002..c1c90eba 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -221,7 +221,8 @@ function defineScope(cls, targetClass, name, params, methods) { - If fetching the Elements on which destroyAll is called results in an error */ function destroyAll(cb) { - targetClass.destroyAll(this._scope, cb); + var where = (this._scope && this._scope.where) || {}; + targetClass.destroyAll(where, cb); } } diff --git a/test/relations.test.js b/test/relations.test.js index 8218c84a..5f52b4c0 100644 --- a/test/relations.test.js +++ b/test/relations.test.js @@ -437,7 +437,7 @@ describe('relations', function () { }); }); - it('should find record on scope', function (done) { + it('should find records on scope', function (done) { Category.findOne(function (err, c) { c.products(function(err, products) { products.should.have.length(2); @@ -476,6 +476,15 @@ describe('relations', function () { }); }); + it('should find records on scope', function (done) { + Category.findOne(function (err, c) { + c.products(function(err, products) { + products.should.have.length(3); + done(); + }); + }); + }); + it('should find record on scope - scoped', function (done) { Category.findOne(function (err, c) { c.productType = 'book'; // temporary, for scoping @@ -497,6 +506,24 @@ describe('relations', function () { }); }); }); + + it('should delete records on scope - scoped', function (done) { + Category.findOne(function (err, c) { + c.productType = 'tool'; // temporary, for scoping + c.products.destroyAll(function(err, result) { + done(); + }); + }); + }); + + it('should find record on scope - verify', function (done) { + Category.findOne(function (err, c) { + c.products(function(err, products) { + products.should.have.length(2); + done(); + }); + }); + }); });