https://www.prisma.io/ logo
#orm-help
Title
# orm-help
g

guilherme

09/27/2022, 4:07 PM
hello guys im trying to return the number of records nested in one model on my database but i am not finding a way. where i want just the number of record where notifications is dismissAt null. but i just want the number not the whole thing.
Copy code
const user = await this.prismaService.user.findUnique({
      where: {
        id: userId,
      },
      select: {
        managing: {
          select: {
            user: {
              select: {
                person: true,
              },
              include: {
                notifications: {
                  where: {
                    dismissAt: null,
                  },
                },
              },
            },
          },
        },
      },
    });
1
r

Raphael Etim

09/27/2022, 5:24 PM
Hi @Clément Guibout 👋 Can you try using this and let me know if it works for you?
Copy code
const user = await this.prismaService.user.findUnique({
    where: {
      id: userId,
    },
    select: {
      managing: {
        select: {
          user: {
            select: {
              person: true,
            },
            select: {
              _count: {
                select: {
                  notifications: {
                    where: {
                      dismissAt: null,
                    },
                  },
                }
                
              }
              
            },
          },
        },
      },
    },
  });
g

guilherme

09/27/2022, 8:07 PM
it work we just have to use "filteredRelationCount" as a preview feature
thanks
r

Raphael Etim

09/28/2022, 2:51 AM
You're welcome.
4 Views