Repository navigation
fix(query): compile relation filters inside where groups and nested relation constraints - #55
Merged
Merged
Conversation
…lation constraints - whereHas/orWhereHas inside a where(callback) group were discarded, because only the group's plain conditions were kept, which widened results silently. They now travel in the group as relation conditions. - whereHas inside another whereHas callback could not be compiled, so the query was refused or handled outside SQL. Nested filters now compile to correlated subqueries on the related table. - Add the QueryRelationCondition where-tree node, compiled by the Kysely adapter; the Prisma compatibility adapter rejects it explicitly. - Correct the update()/updateFrom() docblocks: update() changes the first match, updateFrom() changes every match. - Document nested and grouped relation filters.
The test model borrows the user schema, which has no unitPrice, so raw attribute reads failed the typecheck. Read them through a loosely typed helper. Add the missing trailing newline Prettier expects.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
3m1n3nc3
added a commit
that referenced
this pull request
Oct 10, 2026
fix(query): compile relation filters inside where groups and nested relation constraints
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
Two relation-filter bugs, both found while building a permission-based audience query in an app.
1.
whereHasinside awhere(callback)group was discardedA grouped
wherecallback kept only the group's plain conditions. AnywhereHas/orWhereHasinside it was dropped without an error, so results came back wider than asked for.2.
whereHasnested inside another relation's callback did not compileA relation constraint that itself contained a relation filter couldn't be turned into an adapter spec. So the query was refused or handled outside SQL, and
toSql()didn't show the filter.Fix
QueryRelationCondition({ type: 'relation', filter }) where-tree node.count(*)subquery used by top-levelwhereHas.UnsupportedAdapterFeatureExceptioninstead of silently ignoring it.Also
update()/updateFrom()docblocks.update()changes the first match only, as the guide already says;updateFrom()changes every match.cast-set-symmetry.spec.tsfailedtscbecause its model borrows theuserschema, which has nounitPrice.packages/plugin-clear-router/package.jsonfailedformat:check.Test plan
mainand pass here; the nested test also asserts each query runs as a single SQL statement.pnpm build,pnpm lint,tsc --noEmit(0 errors),pnpm format:checkpnpm test:all: 567 passed, 2 skipped