Does 'query' support subqueries with filters?

Is it possible to define subquery with filters for many to one relation?
1 Reply
tzezar
tzezarOP5mo ago
Oh wow its so easy. Amazing
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()),
},
},
});
Want results from more Discord servers?
Add your server