title: Prisma 3 relation aggregation (sum)
body: <p>I'm having some trouble trying to get sum for related data.</p>
  <p>This is my schema:</p>
  <pre><code>model Vote {
    userId Int
    user   User @relation(fields: [userId], references: [id])
    itemId Int
    item   Item @relation(fields: [itemId], references: [id])
    value  Int
  
    @@id([userId, itemId])
  }
  
  model Item {
    id        Int      @id @default(autoincrement())
    userId    Int
    user      User     @relation(fields: [userId], references: [id])
    listId    Int
    list      List     @relation(fields: [listId], references: [id])
    votes     Vote[]
    body      String   @db.VarChar(255)
    createdAt DateTime @default(now())
    updatedAt DateTime @updatedAt
  }
  
  model List {
    id          Int      @id @default(autoincrement())
    userId      Int
    user        User     @relation(name: &quot;Ownership&quot;, fields: [userId], references: [id])
    items       Item[]
    sharedWith  User[]   @relation(name: &quot;Shared&quot;)
    title       String   @db.VarChar(255)
    description String?
    createdAt   DateTime @default(now())
    updatedAt   DateTime @updatedAt
  }
  
  model User {
    id         Int      @id @default(autoincrement())
    email      String   @unique
    password   String
    name       String?
    lists      List[]   @relation(name: &quot;Ownership&quot;)
    items      Item[]
    votes      Vote[]
    sharedWith List[]   @relation(name: &quot;Shared&quot;)
    createdAt  DateTime @default(now())
    updatedAt  DateTime @updatedAt
  }
  </code></pre>
  <p>What I'm trying to get is:</p>
  <ul>
  <li>1 List by ID</li>
  <li>Included list items</li>
  <li>And for every item sum of the values (from Vote table).</li>
  </ul>
  <p>This is what I came up with:</p>
  <pre class="lang-js prettyprint-override"><code>prisma.list.findUnique({
      where: { id },
      include: {
          items: {
              include: {
                  votes: {
                      include: {
                          _sum: {
                              select: {
                                  value: true,
                              },
                          },
                      },
                  },
              },
          },
      },
  })
  </code></pre>
  <p>I constructed query based on multiple different queries I found online (most of them in Prisam Docs).</p>
  <p>Also I noticed that Prisma Docs are missing a lot of things, like (adding/removing related data - many to many relationship). Are there any better docs, or example project with stuff like these?</p>
  <p>Thanks!</p>