Skip to content

Pass params to pre hooks #5116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -3635,7 +3635,10 @@ Model.compile = function compile(name, schema, collectionName, connection, base)
model.Query.base = Query.base;
applyQueryMethods(model, schema.query);

var kareemOptions = { useErrorHandlers: true };
var kareemOptions = {
useErrorHandlers: true,
numCallbackParams: 1
};
model.$__insertMany = model.hooks.createWrapper('insertMany',
model.insertMany, model, kareemOptions);
model.insertMany = function(arr, options, callback) {
Expand Down
12 changes: 10 additions & 2 deletions test/model.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5345,7 +5345,15 @@ describe('Model', function() {
});
var calledPre = 0;
var calledPost = 0;
schema.pre('insertMany', function(next) {
schema.pre('insertMany', function(next, docs) {
assert.equal(docs.length, 2);
assert.equal(docs[0].name, 'Star Wars');
++calledPre;
next();
});
schema.pre('insertMany', function(next, docs) {
assert.equal(docs.length, 2);
assert.equal(docs[0].name, 'Star Wars');
++calledPre;
next();
});
Expand All @@ -5358,7 +5366,7 @@ describe('Model', function() {
Movie.insertMany(arr, function(error, docs) {
assert.ifError(error);
assert.equal(docs.length, 2);
assert.equal(calledPre, 1);
assert.equal(calledPre, 2);
assert.equal(calledPost, 1);
done();
});
Expand Down