elaranthedreamer
elaranthedreamer
DTDrizzle Team
Created by elaranthedreamer on 8/17/2023 in #help
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?
const res = await db.query.postsTable.findMany({
with: {
user: true,
},
where: (posts, { eq, and }) =>
and(
eq(posts.done, true), //<- This works
eq(posts.user.public, true) // <- This not
),
});
const res = await db.query.postsTable.findMany({
with: {
user: true,
},
where: (posts, { eq, and }) =>
and(
eq(posts.done, true), //<- This works
eq(posts.user.public, true) // <- This not
),
});
7 replies