Considering such models: ```model Wallet { user ...
# orm-help
h
Considering such models:
Copy code
model Wallet {
  user User
  balance Int
  incomingTransactions Transaction[] @relation("incomingTransaction")
  outgoingTransactions Transaction[] @relation("outgoingTransaction")
}

model Transaction {
  id Int 
  change Int
  toWallet Wallet @relation(name: "incomingTransaction")
  fromWallet Wallet? @relation(name: "outgoingTransaction")
}
how can I create a query that creates the transaction and: 1. decrements balance of fromWallet by
change
if specified 2. increments balance of toWallet by
change
3. and actually returns Transaction in the end Couldn't figure it out on my own 😕 Should I maybe just opt in to use $transaction?
✅ 1
h
Yes, you will need to use a
$transaction
here:
Copy code
const data = await prisma.$transaction(async (tx) => {
  const record = await tx.transaction.create({
    // data here
  });

  const updatedRecord = await tx.transaction.update({
    where: { id: record.id },
    data: { toWallet: { increment: change } },
  });
});