Relational Queries: How to query based on the value of a joined table?
I have a table posts, where each post has a uid. I use relational queries to perform a join of the user into the post. Now I want to write a where(..) clause which checks whether the user.public field is set to true. However, the where clause does not allow accessing values of the user but only that of posts. How can I accomplish this?
4 Replies
You can't use a relation in the
eq
function like that. This might be what you're looking for:
But if you are only looking for the posts where the user is public, I would invert it; get the public users, and then pull all the posts from those users that are done:
If you think about how you would do this using only Sql, you would probably use an inner joinThis should only give you the posts that are done with users that are public.
https://orm.drizzle.team/docs/joins#inner-join
Joins [SQL] – DrizzleORM
Drizzle ORM | %s
Thank you so much this helps a lot @angelelz
No problem