Hey guys! im having a question about prisma queri...
# orm-help
m
Hey guys! im having a question about prisma queries when it comes to many to many, lets say i have Products and Users products are generated by admins and users can have few products. products can also be owned by few users. what im trying to do is getting a single user, and getting his products, no success so far, any idea how i can do such thing?
👀 1
l
Im pretty sure you have to create a new table to represent the many to many relationship:
Copy code
model Product {
  id         Int
  title      String
  creator      User  <- One to Many
  creator_id      Int
  users UsersOfProduct[]  <- Many to Many
}

model User {
  id    Int
  name  String
  owned_products UsersOfProduct[] <- Many to Many
  created_products Product[] <- One to Many
}

model UsersOfProduct {
  product       Product
  product_id     Int
  user   User
  user_id Int

  @@id([product_id, user_id])
}
Theres a whole article on this at prisma.io https://www.prisma.io/docs/concepts/components/prisma-schema/relations/many-to-many-relations