mongoose icon indicating copy to clipboard operation
mongoose copied to clipboard

Fix dynamic virtual populate on sub-documents

Open Hybrid-Force opened this issue 3 years ago • 2 comments

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.

Hybrid-Force avatar Sep 17 '22 10:09 Hybrid-Force

I do like the fix that ref() on virtuals is now called on the subdocument rather than the top-level document. But refPath should still be relative to top-level document. Is that possible?

Sure, I will update the patch.

Hybrid-Force avatar Sep 27 '22 10:09 Hybrid-Force

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)

hasezoey avatar Mar 14 '24 16:03 hasezoey

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

vkarpov15 avatar Jun 05 '24 19:06 vkarpov15