Prisma1: Cannot get self-relation with reverse field working.

Created on 5 Jan 2018  ยท  8Comments  ยท  Source: prisma/prisma1

Thanks to doeke for reporting this bug here: https://www.graph.cool/forum/t/1-0-self-relation-with-reverse-field-errors/2066?u=nilan

Cannot get self-relation with reverse field working.

    type DataRow @model {
      id: ID! @unique
      mergedInto: DataRow
      mergedFrom: [DataRow!]!
    }

Deploy:

    DataRow
    ร— The relation field `mergedInto` must specify a `@relation` directive: `@relation(name: "MyRelation")`
    ร— The relation field `mergedFrom` must specify a `@relation` directive: `@relation(name: "MyRelation")`

Next I tried with relation directive specified

    type DataRow @model {
      id: ID! @unique
      mergedInto: DataRow @relation(name: "MergeRelation")
      mergedFrom: [DataRow!]! @relation(name: "MergeRelation")
    }

Deploy:

    DataRow
    ร— A relation directive for a self relation must appear either 1 or 2 times. Relation name: 'MergeRelation'
    ร— A relation directive for a self relation must appear either 1 or 2 times. Relation name: 'MergeRelation'

What does work is if I leave out the reverse field:

    type DataRow @model {
      id: ID! @unique
      mergedInto: DataRow
    }

Most helpful comment

The issue is still in Prisma and is unfortunately blocking my migration from Graphcool 0.x. Can't wait to be able to get Prisma to work :)

All 8 comments

I'm having the same issue. My schema causing it is:

type User {
  id: ID! @unique
  createdAt: DateTime!
  updatedAt: DateTime!
  email: String! @unique
  followers: [User!]! @relation(name: "Following")
  follows: [User!]! @relation(name: "Following")
}

resulting in error:

Deploying service `XXXXX` to stage `dev` on cluster `local`... 29ms
Errors:

  User
    โœ– A relation directive for a self relation must appear either 1 or 2 times. Relation name: 'Following'
    โœ– A relation directive for a self relation must appear either 1 or 2 times. Relation name: 'Following'

The issue is still in Prisma and is unfortunately blocking my migration from Graphcool 0.x. Can't wait to be able to get Prisma to work :)

did e33c780 and 9caf33e fixed that issue? I'm still getting "1 or 2 times" error after 1.0.11 update

Yes, this is supposed to be fixed in 1.0.11. Do you have a reproduction?

I just tried to deploy this datamodel:

type User {
  id: ID! @unique
  name: String!
}

type DataRow {
  id: ID! @unique
  mergedInto: DataRow @relation(name: "MergeRelation")
  mergedFrom: [DataRow!]! @relation(name: "MergeRelation")
}

It was successfully deployed to prisma-us1 and local. You might need to run prisma local upgrade to pull the latest Docker image ๐Ÿ™‚

@marktani:

To go futher from the @pie6k exemple, is this wrong?

type User {
  id: ID! @unique
  email: String! @unique
  ...
  follwers: [User!]! @relation(name: "UsersFollowers")
  following: [User!]! @relation(name: "UsersFollowing")
}

This is now fixed in the latest release.

@johannpinson I am not sure what you mean exactly, can you elaborate your question? ๐Ÿ™‚

In my own schema, to avoid 2 relation with the same name like "UserFollows", I add two different name for the self-relation (so "UserFollowers" and "UserFollowing").

I would like to know if it's a bad idea?

Both approaches result in different data models ๐Ÿ™‚ Which one is the better choice in a concrete context is better discussed in a new question in the Forum.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

schickling picture schickling  ยท  3Comments

tbrannam picture tbrannam  ยท  3Comments

marktani picture marktani  ยท  3Comments

akoenig picture akoenig  ยท  3Comments

marktani picture marktani  ยท  3Comments