Skip to content

Commit

Permalink
fix(populate): handles refPath underneath map of subdocuments
Browse files Browse the repository at this point in the history
Fix #9359
  • Loading branch information
vkarpov15 committed Dec 23, 2021
1 parent 53fd005 commit 9402efd
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/helpers/populate/modelNamesFromRefPath.js
Expand Up @@ -2,6 +2,8 @@

const MongooseError = require('../../error/mongooseError');
const isPathExcluded = require('../projection/isPathExcluded');
const lookupLocalFields = require('./lookupLocalFields');
const mpath = require('mpath');
const util = require('util');
const utils = require('../../utils');

Expand Down Expand Up @@ -44,13 +46,13 @@ module.exports = function modelNamesFromRefPath(refPath, doc, populatedPath, mod
}
}

const refValue = utils.getValue(_refPath, doc);
const refValue = mpath.get(_refPath, doc, lookupLocalFields);
let modelNames = Array.isArray(refValue) ? refValue : [refValue];
modelNames = utils.array.flatten(modelNames);
return modelNames;
}

const refValue = utils.getValue(refPath, doc);
const refValue = mpath.get(refPath, doc, lookupLocalFields);

let modelNames;
if (modelSchema != null && modelSchema.virtuals.hasOwnProperty(refPath)) {
Expand Down

0 comments on commit 9402efd

Please sign in to comment.