title: NestJS-Prisma How to Apply Count Relations
body: <p>I was trying to follow the official prisma documentation about implement the count relations with <a href="https://www.prisma.io/docs/concepts/components/prisma-client/aggregation-grouping-summarizing#count" rel="nofollow noreferrer">prisma client</a>. In the official documentation, it provides an example:</p>
  <pre><code>const usersWithCount = await prisma.user.findMany({
    select: {
      _count: {
        select: { posts: true },
      },
    },
  })
  </code></pre>
  <p>Follow this documentation, I created the following codes in my NestJS project:</p>
  <pre><code>@ApiDefaultResponse({status: 200, description:'Successfully returned customer count'})
  @ApiBadRequestResponse({status:400, description: &quot;Bad Request&quot;})
  @Get('Count')
  async getCustomersCount(){
      return this.prismaService.clinic.findMany({
          select: {
              _count: {
                  select: {customers: true}
              }
          }
      })
  
  }
  </code></pre>
  <p>However, this gave me an error of</p>
  <pre><code>Type '{ _count: { select: { customers: true; }; }; }' is not assignable to type 'clinicSelect'.
    Object literal may only specify known properties, and '_count' does not exist in type 'clinicSelect'.
  </code></pre>
  <p>And for the auto-generated clinicSelect type: I have</p>
  <pre><code>  export type clinicSelect = {
      clinic_id?: boolean
      clinic_name?: boolean
      clinic_address?: boolean
      customers?: boolean | customerFindManyArgs
      isActive?: boolean
    }
  </code></pre>
  <p>The models I used here is similar to the one prisma used in the documentation, the clinic and customers are many to many relationship.</p>
  <p>Other than this one, I can apply other methods showed in the official documentation, for this count relations,</p>
  <blockquote>
  <p>The ability to count relations is available in version 2.20.0 and
  later.</p>
  </blockquote>
  <p>And my prisma version is 2.30.</p>
  <pre><code>prisma -v
  Environment variables loaded from .env
  prisma                : 2.30.0
  @prisma/client        : 2.30.0
  Current platform      : windows
  </code></pre>
  <p>So my question is, why I cannot apply this count relations in my NestJS code? Is this just an issue with the prisma client or It should be written in another way? Thanks for the help!</p>
  <p>Here is my scheme:</p>
  <pre><code>model clinic {
    clinic_id      Int        @id @unique
    clinic_name    String
    clinic_address String
    /// @DtoRelationRequired
    /// @DtoRelationCanConnectOnCreate
    /// @DtoRelationCanConnectOnUpdate
    customers      customer[]
    isActive       Boolean    @default(true)
  }
  
  model customer {
    customer_id         Int          @id @unique
    customer_first_name String?      @db.VarChar(50)
    customer_last_name  String?      @db.VarChar(50)
    customer_address    String?      @db.VarChar(250)
    /// @DtoRelationRequired
    /// @DtoRelationCanConnectOnCreate
    /// @DtoRelationCanConnectOnUpdate
    clinics             clinic[]
    orders              order_info[]
    patient_info        patient[]
    payment_method      String?
    phone               String?
    email               String?
    isActive Boolean @default(true)
  }
  </code></pre>