Prisma referencing Image table. Tell me how you do this!
Unanswered
American black bear posted this in #help-forum
American black bearOP
Hi! Sorry in advance. This is not directly tied to NextJS
Let's say I'm writing a simple blog with Posts and Comments. Both Posts and Comments can have images, which requires a third table Images
The requirements are the following
- Both comments and posts can have multiple images
- We need the images in a separate table, as each image will have other important attributes beside the link
- We will add multiple other tables down the line, which also needs to reference multiple images
In SQL, I would probably add an (enum, foreign key) pair to the Image model to respectively get the table-name and the key in that table, but in Prisma, I am not sure how to do this
Thanks in advance! 😄
Let's say I'm writing a simple blog with Posts and Comments. Both Posts and Comments can have images, which requires a third table Images
model Image {
id String @id @default(cuid())
url String
mimeType String
}
model Post {
id String @id @default(cuid())
content String
images ???
}
model Comment {
id String @id @default(cuid())
text String
images ????
}The requirements are the following
- Both comments and posts can have multiple images
- We need the images in a separate table, as each image will have other important attributes beside the link
- We will add multiple other tables down the line, which also needs to reference multiple images
In SQL, I would probably add an (enum, foreign key) pair to the Image model to respectively get the table-name and the key in that table, but in Prisma, I am not sure how to do this
Thanks in advance! 😄