I recently obtained some self-relation tables directly from a specific Prisma example.
model User {
id Int @id @default(autoincrement())
name String?
followedBy Follows[] @relation("follower")
following Follows[] @relation("following")
}
model Follows {
follower User @relation("follower", fields: [followerId], references: [id])
followerId Int
following User @relation("following", fields: [followingId], references: [id])
followingId Int
@@id([followerId, followingId])
}
I am contemplating the most effective way to determine if one user is following another, as well as methods for following and unfollowing. My initial thought is to directly query/update the Follows table, but I'm uncertain if the followedBy and following fields in the User model will automatically update themselves.