Prisma:1-N 关系中的过滤和计数

问题描述

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")
}

我想为每个 dataProvider 获取有多少个带有 running = true 的应用程序。

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

相应地达到这个结果

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

我试过查询

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

我想我总是得到 {applications: 2} 作为结果 2 到 some,但我只能使用 someeverynone。我怎么了?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)