Hi Prisma family:wave::skin-tone-2: My use case is...
# orm-help
i
Hi Prisma family👋🏻 My use case is to fetch a user's all posts average rating. • The post model contains a column 
user_id
 which is linked to user model. • There is a rating model which contains
user_id
&
post_id
&
value
which stores the rating given on a specific post by a user. • How could I get the average rating. I tried but couldn't found a solution for it. Thanking in advance :)
f
Hi there, it feels like your use case is similar to this one https://www.prisma.io/docs/reference/api-reference/prisma-client-reference#examples-16
i
Thankyou so much @Franco Roura. I found it helpful 😊
🎉 1
const _average_ = _await prisma.rating.groupBy_({
   
_by_:
['user_id'],
   
_where_:
{
     
_post_:
{
       
_user_id_: _Number_(_req.params.userId_),
_      _},
_    _},
   
__avg_:
{
     
_value_: _true_,
_    _},
_  _})
This query helped me to do so.