Allow `after save` hook to see count of records changed (#1231)

* `after save` hook allows count of records changed

* Fix PR linter
This commit is contained in:
Joshua Chaitin-Pollak 2017-04-06 12:02:34 -04:00 committed by Sakib Hasan
parent 6f88cf1930
commit bb3812fbfb
2 changed files with 14 additions and 2 deletions

View File

@ -2267,6 +2267,7 @@ DataAccessObject.destroyAll = function destroyAll(where, options, cb) {
where: where,
hookState: hookState,
options: options,
info: info,
};
Model.notifyObserversOf('after delete', context, function(err) {
cb(err, info);
@ -2686,6 +2687,7 @@ DataAccessObject.updateAll = function(where, data, options, cb) {
data: data,
hookState: hookState,
options: options,
info: info,
};
Model.notifyObserversOf('after save', context, function(err, ctx) {
return cb(err, info);
@ -2803,6 +2805,7 @@ DataAccessObject.prototype.remove =
instance: inst,
hookState: hookState,
options: options,
info: info,
};
Model.notifyObserversOf('after delete', context, function(err) {
cb(err, info);
@ -2829,6 +2832,7 @@ DataAccessObject.prototype.remove =
instance: inst,
hookState: hookState,
options: options,
info: info,
};
Model.notifyObserversOf('after delete', context, function(err) {
cb(err, info);

View File

@ -2748,18 +2748,22 @@ module.exports = function(dataSource, should, connectorCapabilities) {
TestModel.deleteAll(function(err) {
if (err) return done(err);
ctxRecorder.records.should.eql(aCtxForModel(TestModel, {where: {}}));
ctxRecorder.records.should.eql(aCtxForModel(TestModel, {
where: {},
info: {count: 2},
}));
done();
});
});
it('triggers `after delete` hook without query', function(done) {
it('triggers `after delete` hook with query', function(done) {
TestModel.observe('after delete', ctxRecorder.recordAndNext());
TestModel.deleteAll({name: existingInstance.name}, function(err) {
if (err) return done(err);
ctxRecorder.records.should.eql(aCtxForModel(TestModel, {
where: {name: existingInstance.name},
info: {count: 1},
}));
done();
});
@ -2855,6 +2859,7 @@ module.exports = function(dataSource, should, connectorCapabilities) {
ctxRecorder.records.should.eql(aCtxForModel(TestModel, {
where: {id: existingInstance.id},
instance: existingInstance,
info: {count: 1},
}));
done();
});
@ -2867,6 +2872,7 @@ module.exports = function(dataSource, should, connectorCapabilities) {
if (err) return done(err);
ctxRecorder.records.should.eql(aCtxForModel(TestModel, {
where: {name: existingInstance.name},
info: {count: 1},
}));
done();
});
@ -2900,6 +2906,7 @@ module.exports = function(dataSource, should, connectorCapabilities) {
}),
aCtxForModel(TestModel, {
hookState: {foo: 'BAR'},
info: {count: 1},
where: {id: '1'},
instance: existingInstance,
}),
@ -3056,6 +3063,7 @@ module.exports = function(dataSource, should, connectorCapabilities) {
ctxRecorder.records.should.eql(aCtxForModel(TestModel, {
where: {id: existingInstance.id},
data: {name: 'updated name'},
info: {count: 1},
}));
done();
});