Skip to content

Commit

Permalink
fix(model): fixed post('save') callback parameter
Browse files Browse the repository at this point in the history
closes #13026
  • Loading branch information
lpizzinidev committed Feb 14, 2023
1 parent b3e461a commit edd977f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -3807,7 +3807,7 @@ function handleSuccessfulWrite(document) {
}

document.$__reset();
document.schema.s.hooks.execPost('save', document, {}, (err) => {
document.schema.s.hooks.execPost('save', document, [document], {}, (err) => {
if (err) {
reject(err);
return;
Expand Down
22 changes: 22 additions & 0 deletions test/model.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3153,6 +3153,28 @@ describe('Model', function() {
done();
});
});

it('callback should receive parameter of type document after bulkSave (gh-13026)', async function() {
const schema = new Schema({
foo: Boolean,
bar: Boolean
});

schema.post('save', function(doc) {
assert.deepEqual(this, doc);
});

const Test = db.model('Test', schema);

await Test.create({
foo: true,
bar: true
});

const tests = await Test.find();
tests.forEach(t => t.foo = false);
await Test.bulkSave(tests);
});
});
});

Expand Down

0 comments on commit edd977f

Please sign in to comment.