Search code examples
graphqlprismaprisma-graphql

Prisma deploy embedded in two fields error like bug


I would like to have two colums with the same type of data from and to

this is a very simple example about the error

datamodel.prisma file with a one columns from: Address!

            // it runs fine
            type Travel {
              id: ID! @id
              from: Address!
            }
            type Address @embedded {
              district: String!
            }

datamodel.prisma file with two field with the same embedded from: Address! to: Address!

            // it runs fine
            type Travel {
              id: ID! @id
              from: Address!
              to: Address!
            }
            type Address @embedded {
              district: String!
            }           

It throws the error

            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")`     

Solution

  • According to Prisma's documentation on Data Modeling (see also Datamodel (MongoDB) as your use of the @embedded directive hints that you might be using a document database), the name argument of the @relation directive is needed when your data model contains ambiguous relations.

    In your example, there are two different relations between Travel and Address!, so it seems that Prisma wants you to disambiguate those.

    A very similar question appears here (and has a more detailed answer than mine): Can’t create two or more relations to User (from / to) on Event.