Nested many to many relationship prisma

45 Views Asked by At

I use prisma and create a many to many relationship between two tables as follows

model Post {
  id         Int                 @id @default(autoincrement())
  categories CategoriesOnPosts[]
}

model Category {
  id    Int                 @id @default(autoincrement())
  posts CategoriesOnPosts[]
}

model CategoriesOnPosts {
  post       Post     @relation(fields: [postId], references: [id])
  postId     Int
  category   Category @relation(fields: [categoryId], references: [id])
  categoryId Int 

  @@id([postId, categoryId])
}

But I need that third table ( CategoriesOnPosts ) to be in a many-to-many relationship with another table ( likes )

model CategoriesOnPosts {
  likes     likes[]
}

model likes {}

Is this possible, and how to make this relationship between CategoriesOnPosts and likes ?

thank you

0

There are 0 best solutions below