Skip to content

fix: avoid unnecessarily setting populate virtuals to [] if query didn't have populate()#80

Merged
vkarpov15 merged 1 commit intomasterfrom
vkarpov15/gh-79
May 13, 2025
Merged

fix: avoid unnecessarily setting populate virtuals to [] if query didn't have populate()#80
vkarpov15 merged 1 commit intomasterfrom
vkarpov15/gh-79

Conversation

@vkarpov15
Copy link
Copy Markdown
Member

Fix #79
Re: Automattic/mongoose#10816

Summary

Thanks for reporting. We originally added this behavior in a9a8daa for Automattic/mongoose#10816, but this behavior looks to be no longer necessary.

Examples

@vkarpov15 vkarpov15 requested a review from Copilot May 13, 2025 17:50
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes issue #79 by modifying how populate virtuals are handled so that unpopulated virtuals remain undefined instead of being set to default empty values. It also adds test cases for both populated and unpopulated virtuals to ensure the behavior of lean() matches that of toObject().

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
test/index.test.js Added tests verifying that unpopulated virtuals resolve to undefined and populated virtuals default to an empty array when appropriate.
index.js Removed the code that unnecessarily set default values on populated virtuals, along with the helper function isPopulateVirtual.

@vkarpov15 vkarpov15 merged commit 4bf591d into master May 13, 2025
10 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

Development

Successfully merging this pull request may close these issues.

Using .lean() populates missing reference virtuals, but toObject() does not

2 participants