Skip to content

Commit

Permalink
Merge pull request #12266 from Automattic/vkarpov15/fix-discriminator…
Browse files Browse the repository at this point in the history
…-subpopulate-string

fix(populate): handle specifying recursive populate as a string with discriminators
  • Loading branch information
vkarpov15 committed Aug 23, 2022
2 parents 2de1a86 + bf2fe7c commit 8e49fa6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -4704,7 +4704,7 @@ function populate(model, docs, options, callback) {
*/

function _execPopulateQuery(mod, match, select, assignmentOpts, callback) {
const subPopulate = utils.clone(mod.options.populate);
let subPopulate = utils.clone(mod.options.populate);
const queryOptions = Object.assign({
skip: mod.options.skip,
limit: mod.options.limit,
Expand Down Expand Up @@ -4749,6 +4749,8 @@ function _execPopulateQuery(mod, match, select, assignmentOpts, callback) {
if (mod.model.baseModelName != null) {
if (Array.isArray(subPopulate)) {
subPopulate.forEach(pop => { pop.strictPopulate = false; });
} else if (typeof subPopulate === 'string') {
subPopulate = { path: subPopulate, strictPopulate: false };
} else {
subPopulate.strictPopulate = false;
}
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 @@ -6467,7 +6467,7 @@ describe('model: populate:', function() {
return Log.find({}).
populate({
path: 'activity',
populate: { path: 'postedBy' }
populate: 'postedBy'
}).
sort({ seq: -1 });
}).
Expand Down

0 comments on commit 8e49fa6

Please sign in to comment.