P
Prisma•2mo ago
MinatoTW

Check array contains

Hello, what's the correct way to check if an array doesn't have a value? I'm doing this right now but it's not working:
await tx.player.update({
select: { id: true },
where: {
user_id: id,
level: { gte: trait.unlockLevel },
NOT: {
left_traits: { has: level },
right_traits: { has: level },
},
},
data: {
[`${side.toLowerCase()}_traits`]: { push: level },
},
});
await tx.player.update({
select: { id: true },
where: {
user_id: id,
level: { gte: trait.unlockLevel },
NOT: {
left_traits: { has: level },
right_traits: { has: level },
},
},
data: {
[`${side.toLowerCase()}_traits`]: { push: level },
},
});
Both are Int[] arrays and are empty right now, so this should work I think
8 Replies
Prisma AI Help
Prisma AI Help•2mo ago
You're in no rush, so we'll let a dev step in. Enjoy your coffee, or drop into #ask-ai if you get antsy for a second opinion!
Nurul
Nurul•2mo ago
Hey 👋 If I understand correctly you want to check if the array is empty or not, right? Would something like isEmpty work for you? https://www.prisma.io/docs/orm/prisma-client/special-fields-and-types/working-with-scalar-lists-arrays#null-values-in-arrays
Working with scalar lists/arrays (Concepts) | Prisma Documentation
How to read, write, and filter by scalar lists / arrays.
MinatoTW
MinatoTWOP•2mo ago
hello, no I wish to check if the array doesn't have the value already both left and right arrays must not contain level @Nurul (Prisma) sorry to ping but is this not possible?
Nurul
Nurul•2mo ago
Ah, okay! In that case what you are doing seems correct. As per our official example, this should work: https://www.prisma.io/docs/orm/prisma-client/special-fields-and-types/working-with-scalar-lists-arrays#null-values-in-arrays
Working with scalar lists/arrays (Concepts) | Prisma Documentation
How to read, write, and filter by scalar lists / arrays.
No description
MinatoTW
MinatoTWOP•2mo ago
yes it's not working for some reason sadly is it because the array is empty?
Nurul
Nurul•2mo ago
Can you provide a small reproduction so that I can try?
MinatoTW
MinatoTWOP•2mo ago
I managed to fix it just now, I realized there was no AND after the NOT 😅
NOT: {
AND: {
left_traits: { has: level },
right_traits: { has: level },
},
},
NOT: {
AND: {
left_traits: { has: level },
right_traits: { has: level },
},
},
sorry about that
Nurul
Nurul•2mo ago
Ah! Nice catch! I am glad to hear that you managed to fix it 🙌

Did you find this page helpful?