Skip to content

Commit

Permalink
fix(populate): handle embedded discriminator refPath with multiple …
Browse files Browse the repository at this point in the history
…documents

Fix #9153
  • Loading branch information
vkarpov15 committed Jun 30, 2020
1 parent 11371a6 commit c0d56e6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/helpers/populate/getModelsMapForPopulate.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ module.exports = function getModelsMapForPopulate(model, docs, options) {
if (isRefPath && normalizedRefPath != null) {
const pieces = normalizedRefPath.split('.');
let cur = '';
for (const piece of pieces) {
for (let j = 0; j < pieces.length; ++j) {
const piece = pieces[j];
cur = cur + (cur.length === 0 ? '' : '.') + piece;
const schematype = modelSchema.path(cur);
if (schematype != null &&
Expand All @@ -256,7 +257,7 @@ module.exports = function getModelsMapForPopulate(model, docs, options) {
ret = ret.map(v => v === docValue ? SkipPopulateValue(v) : v);
continue;
}
const modelName = utils.getValue(pieces.slice(i + 1).join('.'), subdoc);
const modelName = utils.getValue(pieces.slice(j + 1).join('.'), subdoc);
modelNames.push(modelName);
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/model.populate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9533,7 +9533,7 @@ describe('model: populate:', function() {

return co(function*() {
const doc1 = yield Model.create({ title: 'doc1' });
const doc2 = yield Model.create({
yield Model.create({
title: 'doc2',
items: [{
type: 'link',
Expand Down

0 comments on commit c0d56e6

Please sign in to comment.