[英]PRISMA - 'where' with deeply nested relation
I'm trying to use 'where' on the deeply nested relation (we can paraphrase 'on relation from relation').我正在尝试在深度嵌套的关系上使用“位置”(我们可以解释“关系中的关系”)。
Unfortunately as for 2022-06 in Prisma documentation there is only info about using 'include' with deeply nested relations , nothing about deeply nested relations with 'where'.不幸的是,对于 Prisma 文档中的 2022-06, 只有关于使用“包含”和深度嵌套关系的信息,没有关于“位置”的深度嵌套关系的信息。
Simplified types in Schema.graphql: Schema.graphql 中的简化类型:
type Entity {
id: ID!
company: Company
}
type Company {
id: ID!
entity: Entity!
status: CompanyStatus!
}
type CompanyStatus {
id: ID!
companies: [Company]
}
I want to query Entities and get only these ones, that have companies, that have exact status (let's say with status that has an ID: 1).我想查询实体并只获取这些拥有公司的实体,这些实体具有确切的状态(假设状态具有 ID:1)。
I've tried in multiple ways:我尝试了多种方式:
1) 1)
function entities(parent, args, context, info) {
const where = {
company: { status: {id: 1} }
}
return context.prisma.entities.findMany({where});
}
Returns:回报:
Unknown arg `status` in where.company.status for type CompanyRelationFilter. Did you mean `is`? Available args:\ntype CompanyRelationFilter {\n is?: CompanyWhereInput | Null\n isNot?: CompanyWhereInput | Null\n
It says to try with 'is', so here we have a try with 'is':它说要尝试使用'is',所以这里我们尝试使用'is':
2) 2)
function entities(parent, args, context, info) {
const where = {
company: { is: { status: {id: 1} } }
}
return context.prisma.entities.findMany({where});
}
Returns:回报:
Unknown arg `is` in where.company.is for type CompanyWhereInput. Did you mean `id`? Available args:\ntype CompanyWhereInput {\n AND?: CompanyWhereInput | List<CompanyWhereInput>\n OR?: List<CompanyWhereInput>\n NOT?: CompanyWhereInput | List<CompanyWhereInput>\n id?: IntFilter | String\n entity_id?: IntFilter | Int\n entity?: EntityRelationFilter | EntityWhereInput\n status?: CompanyStatusRelationFilter | CompanyStatusWhereInput\n status_id?: IntFilter | Int
So the advice about using 'is' doesn't seem to work.所以关于使用'is'的建议似乎不起作用。 It advises to use 'status' or 'status_id', which doesn't work (as in the first example).
它建议使用'status' 或'status_id',这不起作用(如在第一个示例中)。
Anyone knows whether use 'where' with deeply nested relations is possible with Prisma?任何人都知道 Prisma 是否可以使用具有深度嵌套关系的“where”? If yes, how to perform it?
如果是,如何执行?
A friend on mine helped me to find a solution.我的一个朋友帮助我找到了解决方案。 You need to use double 'is':
您需要使用双“是”:
function entities(parent, args, context, info) {
const where = {
company: { is: { status: { is {id: 1} } } }
}
return context.prisma.entities.findMany({where});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.