feat(core): per-parent limiting for populated collections#7370
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## next #7370 +/- ##
========================================
Coverage 99.65% 99.65%
========================================
Files 265 265
Lines 27308 27384 +76
Branches 7076 7562 +486
========================================
+ Hits 27214 27290 +76
Misses 88 88
Partials 6 6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
cdfd0a9 to
2c6de2c
Compare
8875833 to
607b961
Compare
15b9edc to
ef4607f
Compare
ef4607f to
c8fb7a8
Compare
…ulateHints When populating to-many relations, all children are loaded for every parent. This adds `limit`, `offset`, and `orderBy` options to `populateHints`, enabling efficient per-parent limiting using `ROW_NUMBER()` window functions for SQL drivers and a `$group`/`$slice` aggregation pipeline for MongoDB. Limited collections are marked as partial and readonly to prevent the UoW from treating unloaded items as removals. JOINED strategy is automatically forced to SELECT_IN when a limit is set. Closes #1059 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Extend the populate-limit suites to exercise code paths that the initial tests did not reach: pivot-table M:N populate without a limit, a nested populate where the limit lives on the child only, a limit without any orderBy (so the OVER clause falls back to partitioning), null/undefined hint values being ignored, and Mongo M:N in both mappedBy and owning- side branches of initializeManyToMany.
c8fb7a8 to
7299143
Compare
B4nan
added a commit
that referenced
this pull request
Apr 19, 2026
## Summary
- Adds `limit`, `offset`, and `orderBy` to `populateHints` for
per-parent collection limiting (e.g., "4 most recent posts per user")
- SQL: uses `ROW_NUMBER() OVER (PARTITION BY <fk> ORDER BY ...)` wrapped
in a subquery
- MongoDB: uses `$group`/`$push`/`$slice` aggregation pipeline
- Limited collections are marked partial + readonly (prevents UoW from
deleting unloaded items)
- JOINED strategy is automatically forced to SELECT_IN when limit is set
```ts
const users = await em.find(User, {}, {
populate: ['posts'],
populateHints: {
posts: { limit: 4, orderBy: { createdAt: 'desc' } },
},
});
```
Closes #1059
🤖 Generated with [Claude Code](https://claude.ai/code)
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
B4nan
added a commit
that referenced
this pull request
Apr 20, 2026
## Summary
- Adds `limit`, `offset`, and `orderBy` to `populateHints` for
per-parent collection limiting (e.g., "4 most recent posts per user")
- SQL: uses `ROW_NUMBER() OVER (PARTITION BY <fk> ORDER BY ...)` wrapped
in a subquery
- MongoDB: uses `$group`/`$push`/`$slice` aggregation pipeline
- Limited collections are marked partial + readonly (prevents UoW from
deleting unloaded items)
- JOINED strategy is automatically forced to SELECT_IN when limit is set
```ts
const users = await em.find(User, {}, {
populate: ['posts'],
populateHints: {
posts: { limit: 4, orderBy: { createdAt: 'desc' } },
},
});
```
Closes #1059
🤖 Generated with [Claude Code](https://claude.ai/code)
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
limit,offset, andorderBytopopulateHintsfor per-parent collection limiting (e.g., "4 most recent posts per user")ROW_NUMBER() OVER (PARTITION BY <fk> ORDER BY ...)wrapped in a subquery$group/$push/$sliceaggregation pipelineCloses #1059
🤖 Generated with Claude Code