Query for Prisma like insert in multiple joined tables

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?
4 Replies
bloberenober
bloberenober16mo ago
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.
sps
sps16mo ago
Alright, Got it!
Md Jahidul Islam milon
so we will always use transaction right whenever you need to insert into multiple tables?
rphlmr ⚡
rphlmr ⚡15mo ago
Yep, this is the way