relation select query with where condition
I want to select all user's tasks where parent id is null.
Can someone help me fix this query please:
these are the tables in question :
10 Replies
the problem here is that
where: isNull(tasks.parentId)
is an error
the error says Object literal may only specify known properties, and where does not exist in type
Can you show the userTasksRelations?
there's another thread about it here https://discord.com/channels/1043890932593987624/1176166096777248829/1176166096777248829
the documentation suggests this is possible here https://orm.drizzle.team/docs/rqb#where--filters
but for some reason the types don't let you run a where on a relation using the query builder.
Drizzle Queries - Drizzle ORM
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
for my current use case i've gotten around it with a join as i don't need to aggregate like here https://orm.drizzle.team/docs/joins#aggregating-results
but in the future i'd really like to avoid this aggregating, and just use the query builder
Joins [SQL] - Drizzle ORM
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
i have the same solution right now, but it's kind of ugly
too many loops just to reformat the result array 😅
this is exactly what i saw and it confused me
in your case it should work fine as its filtering the relation. for me, i'm trying to filter the parent based on the relation content, which doesn't seem possible
in their example it clearly is possible
the
where
key is only available on many relationsi didn't read you comment the first time, sorry 😅
The problem is that
usersTasks
has only one
task. A where is not allowed in a one relation. Because if it works, it would return null
That's how you have it right now anyway
It looks like what you want is to select is only the usersTasks whose tasks has a parentId = null?
In the RQB you can't filter a table by a nested relation
But you can workaround it with a subquery