Jonas Damtoft
02/19/2022, 10:05 AMCharacter
field that references a new characterId
field, why? I want an implicit relations table.
model Character {
id String @id @default(cuid())
name String
friends Character[] @relation("CharacterFriends")
}
I think my current solution will be this:
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.