Fix scoped destroyAll: only use 'where', not full 'filter' args

This commit is contained in:
Fabien Franzen 2014-07-24 15:55:00 +02:00
parent be1a53482a
commit 973c96268f
2 changed files with 30 additions and 2 deletions

View File

@ -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);
}
}

View File

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