Skip to content

Commit c7cc77d

Browse files
mahi656Copilot
andauthored
Update lib/model.js
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent b8c4a1e commit c7cc77d

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

lib/model.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -358,11 +358,11 @@ Model.prototype.$__handleSave = function(options, callback) {
358358
if (this.$isNew) {
359359
// send entire doc
360360
let obj;
361-
if (this.$__schema.options.minimize === false) {
362-
obj = this._doc;
363-
} else {
364-
obj = this.toObject(saveToObjectOptions);
365-
}
361+
// Always use toObject for serialization; control minimize via options
362+
saveToObjectOptions = Object.assign({}, saveToObjectOptions, {
363+
minimize: this.$__schema.options.minimize
364+
});
365+
obj = this.toObject(saveToObjectOptions);
366366
if ((obj || {})._id === void 0) {
367367
// documents must have an _id else mongoose won't know
368368
// what to update later if more changes are made. the user

0 commit comments

Comments
 (0)