Skip to content

Commit

Permalink
fix(populate): make populate virtual consistently an empty array if l…
Browse files Browse the repository at this point in the history
…ocal field is only empty arrays

Fix #8230
  • Loading branch information
vkarpov15 committed Oct 23, 2019
1 parent ca4f52b commit f4bd463
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/model.js
Expand Up @@ -4120,10 +4120,11 @@ function populate(model, docs, options, callback) {
assignmentOpts.excludeId = excludeIdReg.test(select) || (select && select._id === 0);

if (ids.length === 0 || ids.every(utils.isNullOrUndefined)) {
// Ensure that we set populate virtuals with count option to 0 even
// if we don't actually execute a query.
// Ensure that we set populate virtuals to 0 or empty array even
// if we don't actually execute a query because they don't have
// a value by default. See gh-7731, gh-8230
--_remaining;
if (mod.count) {
if (mod.count || mod.isVirtual) {
_assign(model, [], mod, assignmentOpts);
}
continue;
Expand Down

0 comments on commit f4bd463

Please sign in to comment.