Skip to content

Commit 754db14

Browse files
committed
fix(model): allow virtual ref function to return arrays
1 parent 4348fa1 commit 754db14

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

lib/model.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3580,7 +3580,15 @@ function getModelsMapForPopulate(model, docs, options) {
35803580
if (typeof ref === 'function') {
35813581
ref = ref.call(doc, doc);
35823582
}
3583-
modelNames = [ref];
3583+
3584+
// When referencing nested arrays, the ref should be an Array
3585+
// of modelNames.
3586+
if (Array.isArray(ref)) {
3587+
modelNames = ref;
3588+
} else {
3589+
modelNames = [ref];
3590+
}
3591+
35843592
isVirtual = true;
35853593
} else {
35863594
// We may have a discriminator, in which case we don't want to

0 commit comments

Comments
 (0)