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(); + }); + }); + }); });