Salmon Bhai
Salmon Bhai
PPrisma
Created by Salmon Bhai on 2/13/2025 in #help-and-questions
How do I get the count in nested relations.
Here I am trying to retrieve comment count for every post. How would I go about it?
const posts = await prisma.posts.findMany({
where: {
userId,
},
orderBy: [
{ startDate: 'asc' },
],
select: {
id: true,
title: true,
image: true,
publish: true,
comments: {
_count: {
id: true
}
}
}
});
const posts = await prisma.posts.findMany({
where: {
userId,
},
orderBy: [
{ startDate: 'asc' },
],
select: {
id: true,
title: true,
image: true,
publish: true,
comments: {
_count: {
id: true
}
}
}
});
5 replies