Here is my problem, I want to add all the product...
# orm-help
j
Here is my problem, I want to add all the products to the cart based on the productID but whenever I use to create or createMany prisma give me an error to fill the other value but I don't want to create a new entry, I only want to get the existing data (on products based on ID ) to put in the args. or should I add another table?
r
@Joshua Ramin 👋 If I understand correctly, do you just want to add an existing product to the cart? Is the cart already created and can you share the
Product
model as well?
j
Yes, the database i used is mysql
r
Do you want to create a new cart and add the product to the cart?
j
yes,
r
The above
prisma.cart.create
looks correct to me. What’s the error you’re getting?
j
There are no error actually I just want to turn it to a list of product in a cart like Cart -> product 1, product 2 .... like that
r
You already have a 1-many relation of Cart -> Product, so it is automatically a list when you fetch the relation, so you don’t need to do anything. If you want to add multiple products to the cart, you can do this:
Copy code
prisma.cart.create({
  data: {
    userID,
    quantity,
    product: { connect: [{ productID: 'productid-1' }, { productID: 'productid-2' }] }
  }
})
j
thank you
👍 1