Handle many-to-many relations in Prisma with MySQL

I am struggling with creating a schema that works in Prisma with MySQL. I've read an article at prisma.io regarding the subject, but couldn't figure out how to solve my own problem.

Here's the schema:

model User {
  id String @id @default(cuid())
  name String
  shoppingList ShoppingList[]
}

model ShoppingList {
  id String @id @default(cuid())
  name String
  items Item[]
  user User @relation(fields: [userId], references: [id])
  userId String
}

model Item {
  id String @id @default(cuid())
  name String
  productName String
  category String
  shoppingList ShoppingList[] @relation(fields: [shoppingId], references: [id])
  shoppingId String
}


Basically. Every User should be able to have several ShoppingLists. And the ShoppingLists can contain several Items.
Solution
you use @relation and add id when you have one to one or one to many
Was this page helpful?