Filter Posts by categories?
I'm learning drizzle and I've come to a wall,
how do i filter posts by category id bringing posts with all their respective categories?
const postsByCategory = await db
.select()
.from(postsOnCategories)
.leftJoin(posts, eq(postsOnCategories.postId, posts.id))
.leftJoin(categories, eq(postsOnCategories.categoryId, categories.id))
.where(eq(categories.id, 3));
This brings all posts that contain the referenced category but i want them with their category relations so i can show them in cards.5 Replies
Have you looked into the relational query builder?
Drizzle ORM - next gen TypeScript ORM
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
how about u do that server side not db side
The only workaround i found was selecting from postOncategories and getting the posts ids,
then selecting posts using the array
i wanted to do it in a single query
this will correctly return even there are no posts