Query for Prisma like insert in multiple joined tables

Ssps4/10/2023
Is there a way to achieve insert in multiple tables joined by foreign keys in one query like Prisma?
{
orderStatus: OrderStatus.CART,
organization: {
connect: {
id: orgId
}
},
products: {
create: {
price: price,
product: {
connect: {
id: product.id
}
},
quantity: orderProduct.quantity,
taxPercent: taxPercent,
variants: {
createMany: {
data: variantsOnOrder
}
}
}
}
}
{
orderStatus: OrderStatus.CART,
organization: {
connect: {
id: orgId
}
},
products: {
create: {
price: price,
product: {
connect: {
id: product.id
}
},
quantity: orderProduct.quantity,
taxPercent: taxPercent,
variants: {
createMany: {
data: variantsOnOrder
}
}
}
}
}
Or subsequent inserts in a transaction is the way?
Bbloberenober4/10/2023
Prisma doesn't do it in one query because it's impossible to write such a query in SQL. It does multiple queries behind the scenes. With Drizzle, you'll need to write those queries yourself.
Ssps4/11/2023
Alright, Got it!
MJIMd Jahidul Islam milon5/19/2023
so we will always use transaction right whenever you need to insert into multiple tables?
Rrphlmr ⚡5/19/2023
Yep, this is the way

Looking for more? Join the community!