nikos l
02/23/2022, 2:15 PMawait this.prisma.test.updateMany({
where: {
status: 'active',
endsAt: {
lt: new Date(),
},
},
data: {
status: 'expired',
and here the relation...
},
});
Nurul
02/24/2022, 6:54 AMupdateMany
. There’s a request here that you can follow that tracks this. Can you please leave a 👍 to the issue? It helps our engineering and product team in prioritising it.
For your use case, I would suggest using a findMany to get the filtered records and then using update
in a $transaction
to update records with relations.
Here is a reference for $transactions and an example of updating connected relations in update query
const tests = await this.prisma.test.findMany({
where: {
status: 'active',
endsAt: {
lt: new Date(),
},
},
});
await prisma.$transaction(
tests.map(test =>
this.prisma.test.update({
where: { id: test.id },
data: {
status:'expired',
relation:{}
},
})
)
)
nikos l
02/24/2022, 9:44 AM