Skip to content

Commit 8e49fa6

Browse files
authored
Merge pull request #12266 from Automattic/vkarpov15/fix-discriminator-subpopulate-string
fix(populate): handle specifying recursive populate as a string with discriminators
2 parents 2de1a86 + bf2fe7c commit 8e49fa6

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

lib/model.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4704,7 +4704,7 @@ function populate(model, docs, options, callback) {
47044704
*/
47054705

47064706
function _execPopulateQuery(mod, match, select, assignmentOpts, callback) {
4707-
const subPopulate = utils.clone(mod.options.populate);
4707+
let subPopulate = utils.clone(mod.options.populate);
47084708
const queryOptions = Object.assign({
47094709
skip: mod.options.skip,
47104710
limit: mod.options.limit,
@@ -4749,6 +4749,8 @@ function _execPopulateQuery(mod, match, select, assignmentOpts, callback) {
47494749
if (mod.model.baseModelName != null) {
47504750
if (Array.isArray(subPopulate)) {
47514751
subPopulate.forEach(pop => { pop.strictPopulate = false; });
4752+
} else if (typeof subPopulate === 'string') {
4753+
subPopulate = { path: subPopulate, strictPopulate: false };
47524754
} else {
47534755
subPopulate.strictPopulate = false;
47544756
}

test/model.populate.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6467,7 +6467,7 @@ describe('model: populate:', function() {
64676467
return Log.find({}).
64686468
populate({
64696469
path: 'activity',
6470-
populate: { path: 'postedBy' }
6470+
populate: 'postedBy'
64716471
}).
64726472
sort({ seq: -1 });
64736473
}).

0 commit comments

Comments
 (0)