Hey, hoping someone can assist me with a quick iss...
# prisma-client
j
Hey, hoping someone can assist me with a quick issue I have with the Prisma schema.. I am trying to model a character, it has to have a many to many self relation. But it says it is missing the ‘opposite’ relation field. When I format, it adds a
Character
field that references a new
characterId
field, why? I want an implicit relations table.
Copy code
model Character {
  id          String      @id @default(cuid())
  name        String
  friends     Character[] @relation("CharacterFriends")
}
I think my current solution will be this:
Copy code
model Character {
  id              String    @id @default(cuid())
  name            String
  friends         Friends[] @relation("friend")
  friends_ignored Friends[] @relation("friend_ignored") @ignore
}

model Friends {
  character        Character @relation("friend", fields: [characterId], references: [id])
  characterId      String
  ignoredCharacter Character @relation("friend_ignored", fields: [ignoredId], references: [id])
  ignoredId        String

  @@id([characterId, ignoredId])
}
Is there a better way? I also need to make sure I both insert and delete two records whenever I update this, as the friendship should always be mutual.