Hi prisma family:wave: I have a question related t...
# orm-help
i
Hi prisma family👋 I have a question related to
$transaction
query. My current code (which is not working yet) :
const _users_ = _await prisma.user.findMany_({
      
_select_:_ _{ _id_: _true_, _username_: _true_ },
_    _})
_for_ (const _u_ of users) {
      
let_ _uniqueId_ _= _nanoid_()
_await_ _prisma.user.update_({
        
where: { id: parseInt(_u._id) },
        
data: {
          
reference_code: uniqueId +
-${_u._username}` + 
-${_u._id}
,
Copy code
},
Copy code
})`     
}
_await_ _prisma.$transaction_([users])
Actually I want to update each user's reference_code ,for which I need its id and username. How to access the id and username of the user which im currently updating? From the docs I read that its not possible to grab id from find and the use it in update query. How can I solve this?
r
@Ibad Shaikh 👋 Currently this isn’t directly possible with Prisma’s transactions. You would need to use a raw query for this one and that would be easier as well as the current fields can be referenced. We will be introducing long running transactions so I would suggest following this request for more updates 🙂
👍 1
i
@Ryan Thankyou so much for responding. I will wait for this awesome feature in newer versions.
🙌 1
r
@Ibad Shaikh 👋 We have long running transactions rolled out 🎉 You can now run your dependent statements inside a transaction as shown here: https://prisma.slack.com/archives/CA491RJH0/p1623345943442000