DT
Drizzle Team•2w ago
tc

Using relation columns in where clause (Drizzle playground provided)

I have a one-to-one relationship with a schema defined like: https://drizzle.run/uwkkt8l10cgp5okr1r41tjfu When I run that query, I get the following error column agent.deleted does not exist. Why can't you reference relation columns in a top-level where clause? Is there a better way to do this without using the select API with joins?
7 Replies
Angelelz
Angelelz•2w ago
I can't open that playgroud. can you make sure you clicked "share"?
tc
tcOP•2w ago
sorry about that, i did not. it's shared now: https://drizzle.run/uwkkt8l10cgp5okr1r41tjfu
Angelelz
Angelelz•2w ago
This is what you'd do Use a subquery
Angelelz
Angelelz•2w ago
I just added some seed statements
tc
tcOP•2w ago
Got it, thanks for the response! So I guess there isn't any way to query on relations in a single query using the Query API? Your solution works and it provides the data in the structure I was hoping for, but it also requires two trips to the DB 🫤 Do you think this is an intentional design decision or potentially just a missed feature?
Angelelz
Angelelz•2w ago
It does not require two trips to the database, you can delete the first request and is still going to work The subquery is not a request, I wrote it that way for readability
Want results from more Discord servers?
Add your server