drizzle-team / drizzle-team/drizzle-orm

[BUG]: Cannot reference root query alias in nested includes

Open
#5,279 2 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### Report hasn't been filed before.

- [x] I have verified that the bug I'm about to report hasn't been filed before.

### What version of `drizzle-orm` are you using?

0.45.1

### What version of `drizzle-kit` are you using?

0.31.8

### Other packages

_No response_

### Describe the Bug

if I want to include extras in a nested field, I can't access the alias of the root table in order to use in that nested table's alias. Something like this
```ts
await db.query.orders.findMany({
where: // where clause
with: {
orderItems: {
extras: (orderItemsTable) => ({
status: sql.raw(`CASE WHEN ${and(eq(orderItemsTable.key, "Value", eq(orders.key, "Value"))} THEN ${1} ..... END`)
})
}
}
}
```

In this exampe, even though I'm referencing orders table in the ordeerItems.extras, it wont be aliased because I'm not selecting the alias of the order table. Normally if this was an extra on order level, I'd take table from the extras function, but this is on the orderItems level that references order table

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.