簡體   English   中英

PRISMA - 具有深度嵌套關系的“位置”

[英]PRISMA - 'where' with deeply nested relation

我正在嘗試在深度嵌套的關系上使用“位置”(我們可以解釋“關系中的關系”)。

不幸的是,對於 Prisma 文檔中的 2022-06, 只有關於使用“包含”和深度嵌套關系的信息,沒有關於“位置”的深度嵌套關系的信息。

Schema.graphql 中的簡化類型:

type Entity {
  id: ID!
  company: Company
}

type Company {
  id: ID!
  entity: Entity!
  status: CompanyStatus!
}

type CompanyStatus {
  id: ID!
  companies: [Company]
}

我想查詢實體並只獲取這些擁有公司的實體,這些實體具有確切的狀態(假設狀態具有 ID:1)。

我嘗試了多種方式:

1)

function entities(parent, args, context, info) {
  const where = {
    company: { status: {id: 1} }
  }
  return context.prisma.entities.findMany({where});
}

回報:

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

它說要嘗試使用'is',所以這里我們嘗試使用'is':

2)

function entities(parent, args, context, info) {
  const where = {
    company: { is: { status: {id: 1} } }
  }
  return context.prisma.entities.findMany({where});
}

回報:

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

所以關於使用'is'的建議似乎不起作用。 它建議使用'status' 或'status_id',這不起作用(如在第一個示例中)。

任何人都知道 Prisma 是否可以使用具有深度嵌套關系的“where”? 如果是,如何執行?

我的一個朋友幫助我找到了解決方案。 您需要使用雙“是”:

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM