feat: add AND-mode to-many filtering via per-value EXISTS subqueries#1141
Merged
ppetzold merged 4 commits intoppetzold:masterfrom Apr 28, 2026
Merged
Conversation
Owner
|
LGTM. Can you rebase? |
Adds support for $and comparator on to-many filtered columns, allowing callers to express 'entity must have ALL of these related values' semantics. Key changes: - addToManySubFilters: detect $and comparator values on sub-columns and emit one correlated EXISTS subquery per value (ANDed on outer query), instead of a single shared EXISTS where AND conditions on the same column would always be false on a single row - buildExistsQb: accepts existsIndex to make aliases unique per EXISTS (prevents TypeORM alias deduplication collapsing multiple subqueries) - Parameter renaming: recursively renames :paramName references in WHERE conditions of non-first EXISTS subqueries to avoid parameter collision when TypeORM merges subquery parameters into the outer query - FilterComparator exported from paginate.ts for consumer use - ManyToMany junction table support added (cherry-pick of commit 66404d8) - 5 new tests covering OneToMany AND-mode, ManyToMany AND-mode, negative cases, and single-value $and (should behave like OR-mode)
…fe aliases, and validation Address review feedback on the AND-mode to-many filtering feature: - Extract hasExplicitAndComparator helper to reliably detect user-written $and vs default comparator - Export TYPEORM_PARAM_REGEX (handles dots and spread params, skips :: casts) for testability - Scope EXISTS alias/parameter suffixes with pathSlug to prevent collisions across independent to-many paths - Add AddFilterOptions interface (maxAndValues, validateAndComparator) and thread it through addFilter/addToManySubFilters - Guard inverse ManyToMany (parentMeta.inverseRelation) and document column-role swap - Throw on mixed $and + non-$and values, bare $and, $and on scalar columns, and $and + $none/$all - Extract buildSubqueryJoinChain, correlateManyToManyOrFk, renameSubqueryParameters as named inner functions - Add JSDoc to addToManySubFilters and AND-mode section to README with maxAndValues example - Add 11 unit tests (regex + hasExplicitAndComparator) and 8 integration tests (two-path collision, inverse M2M, error conditions)
0dca20e to
5646680
Compare
Contributor
Author
|
Done! |
ppetzold
approved these changes
Apr 28, 2026
Owner
|
🎉 This PR is included in version 13.2.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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.
Adds support for $and comparator on to-many filtered columns, allowing callers to express 'entity must have ALL of these related values' semantics.
Key changes: