Skip to content

Commit bd8fa0d

Browse files
committed
fix: reuse existing hydratedPopulatedDocs option re: #14503
1 parent a4e782d commit bd8fa0d

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

lib/model.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -3959,8 +3959,7 @@ Model.hydrate = function(obj, projection, options) {
39593959
obj = applyProjection(obj, projection);
39603960
}
39613961
const document = require('./queryHelpers').createModel(this, obj, projection);
3962-
options = options || {};
3963-
document.$init(obj, { ...options, hydrate: true });
3962+
document.$init(obj, options);
39643963
return document;
39653964
};
39663965

lib/schema.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2317,7 +2317,7 @@ Schema.prototype.virtual = function(name, options) {
23172317
_v == null ? [] : [_v];
23182318
}
23192319

2320-
if (opts?.hydrate && !options.count) {
2320+
if (opts?.hydratedPopulatedDocs && !options.count) {
23212321
const modelNames = virtual._getModelNamesForPopulate(this);
23222322
const populatedVal = this.$$populatedVirtuals[name];
23232323
if (!Array.isArray(populatedVal) && !populatedVal.$__ && modelNames?.length === 1) {

test/model.hydrate.test.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@ describe('model', function() {
153153

154154
const populated = await User.findOne({ name: 'Alex' }).populate(['stories', 'storiesCount']).lean();
155155
const hydrated = User.hydrate(
156-
JSON.parse(JSON.stringify(populated))
156+
JSON.parse(JSON.stringify(populated)),
157+
null,
158+
{ hydratedPopulatedDocs: true }
157159
);
158160

159161
assert.equal(hydrated.stories[0]._id.toString(), story1._id.toString());

0 commit comments

Comments
 (0)