[英]How to get included model data count in prisma with where clause?
我需要获取带有帖子数的用户详细信息(今天的帖子数)。
const usersWithCount = await prisma.user.findMany({
select: {
_count: {
select: {
posts: {
where: {
createdAt: moment().format("YYYY-MM-DD"),
},
},
recipes: true,
},
},
},
})
您无法过滤关系计数,prisma 目前不支持此功能。 这是在关系计数中添加过滤器的功能请求。 在您的用例中,您可以获得如下所述的过滤关系:
const usersWithCount = await prisma.user.findMany({
select: {
posts: {
where: {
createdAt: moment().format("YYYY-MM-DD"),
},
},
recipes: true
},
});
在上述查询的响应中,您将获得包含满足您的 where 条件的记录的 posts 数组,您可以使用数组的长度作为计数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.