const usersWithCount = await prisma.user.findMany({
include: {
_count: {
select: { posts: true },
},
},
})
/*
{ id: 1, _count: { posts: 3 } },
{ id: 2, _count: { posts: 2 } },
{ id: 3, _count: { posts: 2 } },
{ id: 4, _count: { posts: 0 } },
{ id: 5, _count: { posts: 0 } }
*/
const usersWithCount = await prisma.user.findMany({
include: {
_count: {
select: { posts: true },
},
},
})