Getting errors while making relations between fields

prisma

#1

Getting @relation directive’s errors while linking fields both ways as mentioned below and this model is an example code from here…

I’m facing the same issue in my implementation so, I tried this code but the issue is still same.

type User {
  id: ID! @unique
  writtenStories: [Story!]! @relation(name: "WrittenStories")
  likedStories: [Story!]! @relation(name: "LikedStories")
}

type Story {
  id: ID! @unique
  text: String!
  author: User! @relation(name: "WrittenStories")
  likedBy: [User!]! @relation(name: "LikedStories")
}

Getting errors while deploying prisma model:
User

:heavy_multiplication_x: The field writtenStories must provide a relation link mode. Either specify it on this field or the opposite field. Valid values are: @relation(link: INLINE)

:heavy_multiplication_x: The field likedStories must provide a relation link mode. Either specify it on this field or the opposite field. Valid values are: @relation(link: INLINE)

Story

:heavy_multiplication_x: The field author must provide a relation link mode. Either specify it on this field or the opposite field. Valid values are: @relation(link: INLINE)

:heavy_multiplication_x: The field likedBy must provide a relation link mode. Either specify it on this field or the opposite field. Valid values are: @relation(link: INLINE)

Quick question: Is there any official discord or slack channel ?


#2

The errors indicate that you need a relation link mode.

link is an argument specified on the @relation which:

Specifies how the relation should be represented in the underlying database. The input values for this argument are defined as an enum with the following possible values:

  • INLINE : The relation is represented with foreign keys.
  • TABLE : The relation is represented via a dedicated relation table.

link for reference.

So a fix looks like this:

type User {
  id: ID! @unique
  writtenStories: [Story!]! @relation(name: "WrittenStories")
  likedStories: [Story!]! @relation(name: "LikedStories")
}

type Story {
  id: ID! @unique
  text: String!
  author: User! @relation(name: "WrittenStories", link: INLINE)
  likedBy: [User!]! @relation(name: "LikedStories", link: INLINE)
}

If this example doesn’t work, try replacing INLINE with TABLE. This blog is great to better understand the Datamodel syntax.


#3

Thank you soo much for the clarification it saved my time a lot and thank you for the referenced URL.

I’ll come back with some other doubts, because I’m in a beginner level :slight_smile:


#4

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.