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:
parent
6f88cf1930
commit
bb3812fbfb
|
@ -2267,6 +2267,7 @@ DataAccessObject.destroyAll = function destroyAll(where, options, cb) {
|
||||||
where: where,
|
where: where,
|
||||||
hookState: hookState,
|
hookState: hookState,
|
||||||
options: options,
|
options: options,
|
||||||
|
info: info,
|
||||||
};
|
};
|
||||||
Model.notifyObserversOf('after delete', context, function(err) {
|
Model.notifyObserversOf('after delete', context, function(err) {
|
||||||
cb(err, info);
|
cb(err, info);
|
||||||
|
@ -2686,6 +2687,7 @@ DataAccessObject.updateAll = function(where, data, options, cb) {
|
||||||
data: data,
|
data: data,
|
||||||
hookState: hookState,
|
hookState: hookState,
|
||||||
options: options,
|
options: options,
|
||||||
|
info: info,
|
||||||
};
|
};
|
||||||
Model.notifyObserversOf('after save', context, function(err, ctx) {
|
Model.notifyObserversOf('after save', context, function(err, ctx) {
|
||||||
return cb(err, info);
|
return cb(err, info);
|
||||||
|
@ -2803,6 +2805,7 @@ DataAccessObject.prototype.remove =
|
||||||
instance: inst,
|
instance: inst,
|
||||||
hookState: hookState,
|
hookState: hookState,
|
||||||
options: options,
|
options: options,
|
||||||
|
info: info,
|
||||||
};
|
};
|
||||||
Model.notifyObserversOf('after delete', context, function(err) {
|
Model.notifyObserversOf('after delete', context, function(err) {
|
||||||
cb(err, info);
|
cb(err, info);
|
||||||
|
@ -2829,6 +2832,7 @@ DataAccessObject.prototype.remove =
|
||||||
instance: inst,
|
instance: inst,
|
||||||
hookState: hookState,
|
hookState: hookState,
|
||||||
options: options,
|
options: options,
|
||||||
|
info: info,
|
||||||
};
|
};
|
||||||
Model.notifyObserversOf('after delete', context, function(err) {
|
Model.notifyObserversOf('after delete', context, function(err) {
|
||||||
cb(err, info);
|
cb(err, info);
|
||||||
|
|
|
@ -2748,18 +2748,22 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
|
|
||||||
TestModel.deleteAll(function(err) {
|
TestModel.deleteAll(function(err) {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
ctxRecorder.records.should.eql(aCtxForModel(TestModel, {where: {}}));
|
ctxRecorder.records.should.eql(aCtxForModel(TestModel, {
|
||||||
|
where: {},
|
||||||
|
info: {count: 2},
|
||||||
|
}));
|
||||||
done();
|
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.observe('after delete', ctxRecorder.recordAndNext());
|
||||||
|
|
||||||
TestModel.deleteAll({name: existingInstance.name}, function(err) {
|
TestModel.deleteAll({name: existingInstance.name}, function(err) {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
ctxRecorder.records.should.eql(aCtxForModel(TestModel, {
|
ctxRecorder.records.should.eql(aCtxForModel(TestModel, {
|
||||||
where: {name: existingInstance.name},
|
where: {name: existingInstance.name},
|
||||||
|
info: {count: 1},
|
||||||
}));
|
}));
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
@ -2855,6 +2859,7 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
ctxRecorder.records.should.eql(aCtxForModel(TestModel, {
|
ctxRecorder.records.should.eql(aCtxForModel(TestModel, {
|
||||||
where: {id: existingInstance.id},
|
where: {id: existingInstance.id},
|
||||||
instance: existingInstance,
|
instance: existingInstance,
|
||||||
|
info: {count: 1},
|
||||||
}));
|
}));
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
@ -2867,6 +2872,7 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
ctxRecorder.records.should.eql(aCtxForModel(TestModel, {
|
ctxRecorder.records.should.eql(aCtxForModel(TestModel, {
|
||||||
where: {name: existingInstance.name},
|
where: {name: existingInstance.name},
|
||||||
|
info: {count: 1},
|
||||||
}));
|
}));
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
@ -2900,6 +2906,7 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
}),
|
}),
|
||||||
aCtxForModel(TestModel, {
|
aCtxForModel(TestModel, {
|
||||||
hookState: {foo: 'BAR'},
|
hookState: {foo: 'BAR'},
|
||||||
|
info: {count: 1},
|
||||||
where: {id: '1'},
|
where: {id: '1'},
|
||||||
instance: existingInstance,
|
instance: existingInstance,
|
||||||
}),
|
}),
|
||||||
|
@ -3056,6 +3063,7 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
ctxRecorder.records.should.eql(aCtxForModel(TestModel, {
|
ctxRecorder.records.should.eql(aCtxForModel(TestModel, {
|
||||||
where: {id: existingInstance.id},
|
where: {id: existingInstance.id},
|
||||||
data: {name: 'updated name'},
|
data: {name: 'updated name'},
|
||||||
|
info: {count: 1},
|
||||||
}));
|
}));
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue