首页 > 解决方案 > 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")`     

标签: graphqlprismaprisma-graphql

解决方案


根据 Prisma 关于数据建模的文档(另请参阅Datamodel (MongoDB),因为您使用@embedded指令提示您可能正在使用文档数据库),当您的数据模型包含不明确的关系时,需要使用指令的name参数。@relation

Travel在您的示例中,和之间有两种不同的关系Address!,因此 Prisma 似乎希望您消除这些歧义。

这里出现了一个非常相似的问题(并且有比我更详细的答案):Can't create two or more relationship to User (from / to) on Event


推荐阅读