Good way to do many to many relationship Prisma
I have these schemas where I want to create a many to many relationship between the Xyz table to the subcategory as well as between the Kva table to the subcategory. This is a schema sketch of how I would want to do it but I get the error: Error validating: Embedded many-to-many relations are not supported on MySQL. Please use the syntax defined in https://pris.ly/d/relational-database-many-to-many
Is there any way to do it without intermediate tables? Will add up to a lot of tables over time 🙂
model Subcategory {
id String @id @default(cuid())
name String
xyzs Xyz[] @relation("XyzSubcategory")
kvas Kva[] @relation("KvaSubcategory")
}
model Xyz {
id String @id @default(cuid())
questionPrompt String @db.Text
...
subcategories Subcategory[] @relation("XyzSubcategory", references: [id], fields: [subcategoryId])
subcategoryId String?
}
model Kva {
id String @id @default(cuid())
questionPrompt String @db.Text
...
subcategories Subcategory[] @relation("KvaSubcategory", references: [id], fields: [subcategoryId])
subcategoryId String?
}
1 Reply
OwO7 from what i know there are 2 main ways to define many to many relations in prisma
Implicit relation table (prisma will create the relation table for you)
Explicit relation table (you define the relation table, allows for custom fields on relation)