javascript - 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 to 的结果some
,但我只能使用some
,every
和none
。我错了什么?
解决方案
推荐阅读
- python - Python selenium web 抓取数据到 csv 导出
- date - MS Access:将日期“2020 年 12 月 3 日”导入“日期/时间”列会出错,我如何让它识别出它是一个日期?
- python - 如何使导入的变量透明地调用函数
- reactjs - 如何从 Reactjs 网站复制导航
- javascript - 猫鼬(建造者模式)链式方法如何在幕后工作
- kotlin - Kotlin 聚合连续列表元素
- python - 为什么当我用 K-means 进行 4 个聚类时,我只有一个 intertia 而不是 4 个?
- python - Pyinstaller:制作了一个 exe 但无法正常工作。如何修复这些错误
- javascript - 侧边菜单打开时如何触发功能 | 离子反应
- swift - Swift - 停止截断 UIButton titleLabel