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
Dan
Dan2y 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 | Shootmail
SPS | ShootmailOP2y 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 ⚡2y ago
Yep, this is the way
Want results from more Discord servers?
Add your server