Skip to content

Commit

Permalink
hydratedPopulatedDocs option
Browse files Browse the repository at this point in the history
  • Loading branch information
IslandRhythms committed Feb 13, 2024
1 parent e80cff1 commit e6769c9
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
5 changes: 2 additions & 3 deletions lib/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -767,15 +767,14 @@ function init(self, obj, doc, opts, prefix) {
}
} else {
// Retain order when overwriting defaults
if (doc.hasOwnProperty(i) && obj[i] !== void 0) {
if (doc.hasOwnProperty(i) && obj[i] !== void 0 && !opts.hydratedPopulatedDocs) {
delete doc[i];
}
if (obj[i] === null) {
doc[i] = schemaType._castNullish(null);
} else if (obj[i] !== undefined) {
const wasPopulated = obj[i].$__ == null ? null : obj[i].$__.wasPopulated;

if (schemaType && !wasPopulated) {
if ((schemaType && !wasPopulated) && !opts.hydratedPopulatedDocs) {
try {
if (opts && opts.setters) {
// Call applySetters with `init = false` because otherwise setters are a noop
Expand Down
1 change: 0 additions & 1 deletion test/model.hydrate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ describe('model', function() {
const company = { _id: new mongoose.Types.ObjectId(), name: 'Booster', users: [users[0]] };

const C = Company.hydrate(company, null, { hydratedPopulatedDocs: true });
console.log('what is C', C);
assert.equal(C.users[0].name, 'Val');
});
});
Expand Down

0 comments on commit e6769c9

Please sign in to comment.