Skip to content

Conversation

vkarpov15
Copy link
Collaborator

Fix #15627

Summary

In #15627, OP was looking to hydrate documents with some virtual properties that were computed using the aggregation framework. This PR adds a virtuals: true option to Model.hydrate() which sets any virtuals that are present in the data being hydrated.

Examples

@vkarpov15 vkarpov15 added this to the 8.19 milestone Sep 20, 2025
Copy link
Contributor

@Copilot 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 adds a virtuals: true option to Model.hydrate() to allow setting virtual properties when hydrating documents from raw data, addressing issue #15627. The feature enables hydrating documents with virtual properties computed via aggregation pipelines.

Key changes:

  • Adds virtuals option parameter to Model.hydrate() method
  • Implements virtual property setting logic during document initialization
  • Adds validation to prevent conflicting option combinations

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
lib/model.js Adds virtuals option parameter and validation for option conflicts
lib/document.js Implements virtual property setting logic during document initialization
lib/schema/subdocument.js Passes options parameter to subdocument initialization
lib/schema/documentArray.js Passes options parameter to document array element initialization
lib/schema/map.js Spreads options parameter when casting map values
test/model.test.js Comprehensive test coverage for virtual hydration across different schema types

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@vkarpov15 vkarpov15 changed the base branch from master to 8.19 September 22, 2025 14:40
@vkarpov15 vkarpov15 merged commit 1d424ee into 8.19 Sep 22, 2025
42 checks passed
@hasezoey hasezoey deleted the vkarpov15/gh-15627 branch September 23, 2025 06:59
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.

Virtuals do not get hydrated wth aggregations
2 participants