You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
$expr inside relation filters can't reference the filtered model (missing FROM-clause entry) #2863
$expr types its expression builder with the filtered model as the scope (ExpressionBuilder<DB, Model>), so qualified references like 'User.email' type-check. That holds for top-level filters, where the table is selected as "User". Relation filters, though, select the related model under a generated alias (e.g. "User" as "$$_Post$author"), so the same reference fails at runtime:
// works - top-level filter, the table is selected as "User"awaitdb.user.findMany({where: {$expr: (eb)=>eb('User.email','like','%@zenstack.dev')},});// type-checks, but fails with: missing FROM-clause entry for table "User"awaitdb.post.findMany({where: {author: {$expr: (eb)=>eb('User.email','like','%@zenstack.dev')}},});
Unqualified references (eb('email', ...)) work because they resolve against the innermost table. They break down once the expression contains a subquery with a same-named column, e.g. a correlated subquery that needs the outer row's id, and $expr has no way to learn the real alias.
Expected: $expr gets the alias of the filtered model so expressions can qualify references, the same way computed field implementations already receive modelAlias in their context.
Proposed (non-breaking) fix: pass a second context argument with modelAlias to $expr:
Activity
ymc9 commentedon Oct 27, 2026
Released in v3.10.0 via #2864.