drizzle-team / drizzle-team/drizzle-orm
[BUG]: view with `join` in the query builder generate invalid SQL
- 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.44.0
### What version of `drizzle-kit` are you using?
n/a
### Other packages
_No response_
### Describe the Bug
This query is unable to find "caretakerName" and instead generates an SQL query with "undefined".
```ts
import { drizzle } from "drizzle-orm/node-postgres";
import { pgTable, pgView } from "drizzle-orm/pg-core";
import { eq } from "drizzle-orm";
const animal = pgTable("animal", (t) => ({
id: t.text().primaryKey(),
name: t.text().notNull(),
caretakerId: t.text().notNull(),
}));
const caretaker = pgTable("caretaker", (t) => ({
id: t.text().primaryKey(),
caretakerName: t.text().notNull(),
}));
const animalWithCaretakerView = pgView("animal_with_caretaker_view").as(
(qb) =>
qb
.select({
id: animal.id,
animalName: animal.name,
caretakerName: caretaker.caretakerName,
})
.from(animal)
.innerJoin(caretaker, eq(animal.caretakerId, caretaker.id)),
);
const schema = { animal, caretaker, animalWithCaretakerView };
const db = drizzle("", {schema})
console.log(db.select().from(animalWithCaretakerView).toSQL().sql)
// select "id", "name", "undefined" from "animal_with_caretaker_view"
```
Contributor guide
Assessment
This issue has not been assessed yet.