Title
h

Hei

11/21/2021, 8:20 AM
Hi, How do I group and sum records within Implicit Many to Many. Currently I have a working prisma query but I wonder if there's another way in it.
const countTags = await ctx.prisma.tag.findMany({
    select: {
      name: true,
      _count: {
        select: {
          questions: true,
        },
      },
    },
  });
Since its implicit I cannot call the third table to query it directly. Here's my schema:
model Question {
  id        Int      @id @default(autoincrement())
  title     String
  content   String
  tags      Tag[]
}

model Tag {
  id   Int    @id @default(autoincrement())
  name String @unique
  questions Question[]
}
r

Ryan

11/22/2021, 5:35 AM
@Hei 👋 This is the only way to add this as you won’t get access to the relation table when using implicit many-to-many relations.
h

Hei

11/22/2021, 5:37 AM
Okay, thanks for the confirmation.
👍 1