Mike Borozdin
Mike Borozdin
DTDrizzle Team
Created by Mike Borozdin on 2/22/2024 in #help
query.with like results for innerJoin
If I so something like:
db.select(Product).innerJoin(Category)// and the rest
db.select(Product).innerJoin(Category)// and the rest
I get an array that looks like {Product: {}, Category: {}}[] But is there a way to return an array of products that has a an attibute of Category? Like we do with query() and with(). The reason for the question is the issue with where inside with https://discord.com/channels/1043890932593987624/1210347617364484096/1210347617364484096
1 replies
DTDrizzle Team
Created by Mike Borozdin on 2/22/2024 in #help
How do I use `where` inside `with`?
There's this example on the query() page (https://orm.drizzle.team/docs/rqb)
await db.query.posts.findMany({
where: (posts, { eq }) => (eq(posts.id, 1)),
with: {
comments: {
where: (comments, { lt }) => lt(comments.createdAt, new Date()),
},
},
});
await db.query.posts.findMany({
where: (posts, { eq }) => (eq(posts.id, 1)),
with: {
comments: {
where: (comments, { lt }) => lt(comments.createdAt, new Date()),
},
},
});
But I'm getting a TypeScript error saying there could be no where inside with. I'm on drizzle-orm 0.29
4 replies