Merge pull request #187 from fabien/fix/scope-destroy

Fix scoped destroyAll: only use 'where', not full 'filter' args
This commit is contained in:
Raymond Feng 2014-07-24 08:48:46 -07:00
commit e8863db928
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 - If fetching the Elements on which destroyAll is called results in an error
*/ */
function destroyAll(cb) { 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) { Category.findOne(function (err, c) {
c.products(function(err, products) { c.products(function(err, products) {
products.should.have.length(2); 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) { it('should find record on scope - scoped', function (done) {
Category.findOne(function (err, c) { Category.findOne(function (err, c) {
c.productType = 'book'; // temporary, for scoping c.productType = 'book'; // temporary, for scoping
@ -498,6 +507,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();
});
});
});
}); });
describe('belongsTo', function () { describe('belongsTo', function () {