PrismaP
Prisma2y ago
5 replies
Fervore

Nested relation query help

Hello, I was trying to query users, then I added the implementation to show payments but now I realize it was bringing payments of all users from the membership instead of bringing all payments of that specific user for each specific membership. Is there a way to do this query in the same object or is there a way to reference the current user for each index of the array?
prisma.user.findMany({
  orderBy: {
    id: 'desc',
  },
  include: {
    memberships: {
      include: {
        payments: {
          take: 1,
          orderBy: {
            endDate: 'asc'
          }
        }
      }
    }
  }
})


Example of what It would be ideal but ofc it doesn't work
prisma.user.findMany({
  orderBy: {
    id: 'desc',
  },
  include: {
    memberships: {
      include: {
        payments: {
          where: {
            memberId: "current_member_id??"
          },
          take: 1,
          orderBy: {
            endDate: 'asc'
          }
        }
      }
    }
  }
})
Was this page helpful?