mongoose
mongoose copied to clipboard
Fix dynamic virtual populate on sub-documents
Fix #12363
Summary Apply dynamic ref getter of virtual population on sub-documents instead of the parent document.
Mongoose supports dynamic virtual populate via ref and refPath options. However, the ref function is called on the parent document, and refPath is relative to the parent document. It does not make much sense for dynamic virtual populates defined on nested schemas, because the child schema has no knowledge of the parent schema.
After this patch, ref is called on sub-document, and refPath is relative to sub-document instead of the parent document.
I do like the fix that
ref()on virtuals is now called on the subdocument rather than the top-level document. ButrefPathshould still be relative to top-level document. Is that possible?
Sure, I will update the patch.
seeing as this PR has been open for quite some time with no activity and changes were requested, should this PR be closed?
(from what it looks like this PR was targeting ~6.7, and now mongoose is at 8)
Closing this in favor of #14652, which fixes OP's problem with fewer changes. We will still need to release this in the next major release though, because #14652 is backwards breaking