-
Notifications
You must be signed in to change notification settings - Fork 109
Open
Description
- I've validated the bug against the latest version of DB packages
Describe the bug
QueryCompilationError: Input for alias "parent" (collection "items") not found in inputs map. Available keys: collection
Happens when subquery can be optimized away to just its source collection and join source alias is different than subquery from alias
To Reproduce (example)
Steps to reproduce the behavior:
- Create collection:
const collection = createCollection(
localOnlyCollectionOptions({
id: 'items',
getKey: item => item.id,
schema: z.object({
id: z.int(),
parentId: z.int().nullable(),
name: z.string(),
}),
})
)- Use useLiveQuery with a simple subquery:
const { data } = useLiveQuery(q => {
const subquery = q.from({ collection })
return q
.from({ collection })
.join({ parent: subquery }, ({ parent, collection }) =>
eq(parent.id, collection.parentId)
)
})- Observe the error in console or logs:
QueryCompilationError: Input for alias "parent" (collection "items") not found in inputs map. Available keys: collection
Expected behavior
The subquery should resolve correctly even when the optimizer collapses it to its source collection. The join alias should remain valid and consistent.
Additional context
It doesn’t have to be a self-join - the same issue occurs with any subquery that’s optimized away to its base collection while using a different alias in the join.
Metadata
Metadata
Assignees
Labels
No labels