Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow calling parent() on parent, allow accessing parent's virtual from child subdoc #73

Merged
merged 2 commits into from
Sep 3, 2024

Conversation

vkarpov15
Copy link
Member

Fix #65
Fix #64

Summary

#64 points out that, because mongoose-lean-virtual applies virtuals to child subdocs before their parents, that makes it tricky to use parent virtuals in child subdocs. This change was intentional with #28, and we can't change the subdoc traversal order without a backwards breaking change. But, given that parent() is the only way to get a subdocument's parent, mongoose-lean-virtuals can apply virtuals in the parent() call to ensure the child subdoc gets the parent doc with virtuals applied.

This can create issues if a subdocument calls parent(), and then the parent tries to access one of the subdocument's virtuals. The subdocument virtual won't exist yet. But this case is hopefully unlikely.

I also bumped ESLint, fixed some lint warnings, added parent() to TypeScript type defs, and fixed #64 (also #66) because that's just a one-line fix.

Examples

@vkarpov15 vkarpov15 merged commit 6739f69 into master Sep 3, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant