Problem
Currently, if I try to sort users based on number of posts they have below is the query to be executed.
const getUsers = await prisma.user.findMany({ take: 10, orderBy: { posts: { _count:
‘desc’, }, }, })
But, if I want to sort users based on number of posts who have a postname as ‘AdamCopeland’, I seemingly cannot.
It would be better to have something like this ->
const getUsers = await prisma.user.findMany({
take: 10,
orderBy: {
posts: {
_count: {
where:{
name : "AdamCopeland"
},
value:"desc" //order of sort
},
},
},
})
New contributor
Suyash Singh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.