drizzle-team / drizzle-team/drizzle-orm
[BUG]: Cannot filter data using attached table's column values
- Dominant language
- TypeScript
- Stars
- 35.8k
- Forks
- 1.6k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 4
Description
### What version of `drizzle-orm` are you using?
0.30.6
### What version of `drizzle-kit` are you using?
0.20.14
### Describe the Bug
When using the non-SQL-like querying method, I use `with` to attach another table to my output which uses the relation that I have created. This is fine, but I want to filter these results based on a column within that other table that I referenced; this does not work.
For example this code gives the following error:
```ts
const student = await db.query.students.findFirst({
where: (student, { eq }) => eq(student.person.email, session.user.email),
with: { person: true },
});
```
```
Property 'person' does not exist on type '{ ... }'.
```
### Expected behavior
This should just work.
My current work-around is to fetch twice:
```ts
const person = await db.query.persons.findFirst({
where: (person, { eq }) => eq(person.email, session.user.email),
});
const student = await db.query.students.findFirst({
where: (student, { eq }) => eq(student.id, person.id),
});
```
### Environment & setup
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.