graphql - Prisma 部署嵌入两个字段错误,如 bug
问题描述
我想有两个具有相同类型数据的列
from
,并且to
这是一个关于错误的非常简单的例子
datamodel.prisma
包含一列的文件from: Address!
// it runs fine
type Travel {
id: ID! @id
from: Address!
}
type Address @embedded {
district: String!
}
datamodel.prisma
具有相同嵌入的两个字段的文件from: Address!
to: Address!
// it runs fine
type Travel {
id: ID! @id
from: Address!
to: Address!
}
type Address @embedded {
district: String!
}
它抛出错误
Errors:
Travel
✖ The relation field `from` must specify a `@relation` directive: `@relation(name: "MyRelation")`
✖ The relation field `to` must specify a `@relation` directive: `@relation(name: "MyRelation")`
解决方案
根据 Prisma 关于数据建模的文档(另请参阅Datamodel (MongoDB),因为您使用@embedded
指令提示您可能正在使用文档数据库),当您的数据模型包含不明确的关系时,需要使用指令的name
参数。@relation
Travel
在您的示例中,和之间有两种不同的关系Address!
,因此 Prisma 似乎希望您消除这些歧义。
这里出现了一个非常相似的问题(并且有比我更详细的答案):Can't create two or more relationship to User (from / to) on Event。
推荐阅读
- javascript - Chrome 扩展:点击 popup.js 激活并执行 background.js
- .net - 在工厂中订阅事件处理程序
- c# - LeanTween “from-to”值动画
- python - 从 Python 文件中获取变量并在 Flask 中显示
- mysql - 将结果加入新表?
- python - Python:如何获取每个项目在多个列表中的位置的统计信息?
- javascript - Promise.all 返回双精度数组
- java - 从树构建 JPA 规范
- azure-cosmosdb - 如何在折叠 gremlin 之后使用以前存储的项目
- javascript - 在 vue 的不同位置渲染两个单选按钮