Hey Is there a way to perform this query? I want...
# orm-help
j
Hey Is there a way to perform this query? I want to update records that 'id' is in the id_lists array.
Copy code
await prisma.campaigns.update({
        where: {
             id:{
                includes: id_lists
             }
        },
        data: {
            credits: {
                decrement: 10000
            }
        }
    })
r
Not sure if this is natively supported in Prisma. But as an alternative, you can use this:
Copy code
await prisma.$transaction([...id_lists.map(id => prisma.campaigns.update({
    where: {
        id
    },
    data: {
        credits: {
            decrement: 10000
        }
    }
})])
Though maybe it's not effective since this means you run
n
transaction query.
r
@Jijin P 👋 Could you try
updateMany
in this case? Something like:
Copy code
await prisma.campaigns.updateMany({
        where: {
             id:{
                in: id_lists
             }
        },
        data: {
            credits: {
                decrement: 10000
            }
        }
    })
👍 2
j
@Ryan That works
💯 1