KJReactor
08/13/2021, 10:37 PMRyan
08/16/2021, 7:52 AMKJReactor
08/16/2021, 2:55 PMmodel Post {
id Int @default(autoincrement()) @id
author User @relation("Post_authorToUser", references: [id])
favoritedBy User? @relation("Post_favoritedByToUser", references: [id])
}
model User {
id Int @default(autoincrement()) @id
writtenPost Post[] @relation("Post_authorToUser")
favoritedPosts Post[] @relation("Post_favoritedByToUser")
}
KJReactor
08/16/2021, 2:56 PMKJReactor
08/16/2021, 2:59 PMmodel Post {
id Int @default(autoincrement()) @id
author User @relation("Post_authorToUser", references: [id])
favoritedBy Int
user User? @relation(fields: "favoritedBy" , references: [id])
}
Ryan
08/18/2021, 4:40 AMmodel Post {
id Int @id @default(autoincrement())
author User @relation("Post_authorToUser", references: [id], fields: [userId])
favoritedBy User? @relation("Post_favoritedByToUser", references: [id], fields: [favoritedById])
userId Int
favoritedById Int?
}
model User {
id Int @id @default(autoincrement())
writtenPost Post[] @relation("Post_authorToUser")
favoritedPosts Post[] @relation("Post_favoritedByToUser")
}
The reason is that you are pointing to the same model twice via writtenPost
and favoritedPosts
so you need to provide the opposite relation with the foreign key twice as well.