Prisma: filtering and count in 1-N relationship

Viewed 512
model DataProvider {
  id              Int
  name            String
  applications    Application[]
  @@map("data_providers")
}

model Application {
  id                   Int
  name                 String
  data_provider_id     Int
  running              Boolean
  data_providers       DataProvider 
  @@map("applications")
}

I want to get for each dataProvider how many applications with running = true there are.

DataProvider                Application
-----------------           -----------------------------------------------
id     | name               id     | name    | data_provider_id  | running
-----------------           -----------------------------------------------
1      | dp1                2      | app2    | 1                 | true                  
                            -----------------------------------------------
                            3      | app3    | 1                 | false 

accordingly to achieve this result

dataProvider = {id: 1, name: 'dp1', _count: {applications: 1}}

I tried with query

this.prisma.dataProvider.findMany({
    include: {
        _count: {
            select: {
                applications: true
            }
        }
    },
    where: {
        applications: {
            some: {
                running: {
                    equals:  true
                }
            }
        }
    },
})

I guess I always get {applications: 2} as a result 2 to some, but I can use only some, every and none. What am I wrong?

0 Answers
Related