I've found the solution here https://github.com/prisma/prisma/discussions/8216#discussioncomment-992302
It should be like this instead apparently.
await prisma.product.findMany({
where: {
AND: [
{ price: 21.99 },
{ filters: { some: { name: 'ram', value: '8GB' } } },
{ filters: { some: { name: 'storage', value: '256GB' } } },
],
},
})
Answer from Manish Karki on Stack OverflowUse multiple conditions inside AND operator in a nested relation
how to use OR array inside AND prisma - Stack Overflow
How to correctly use the "AND" operator in Prisma?
OR operator results in a query with AND
This is the right solution, the authorship is not mine, the guys helped me find it.
const product = await this.prismaService.product.findMany({
where: {
AND: [
{ price: 21.99 },
{ options: { some: { title: 'invertor', description: '25' } } },
{ options: { some: { title: 'type', description: 'invertor' } } },
{ options: { some: { title: 'WiFi:', description: 'yes' } } },
],
},
include: { options: true },
});
It seems like the issue might be related to the way you are using the AND operator within the some filter. The some filter is designed to check if at least one element in the array satisfies the conditions, and the AND operator inside it might not be working as expected.
You can try below update version - old
const product = await this.prismaService.product.findMany({
where: {
options: {
every: {
OR: [
{ title: 'square', description: '20' },
{ title: 'type', description: 'invertor' },
],
},
},
},
include: { options: true },
});
I replaced the some filter with the every filter and used OR conditions within it. This should find products that have at least one option with either the specified title and description
New Query
const product = await this.prismaService.product.findMany({
where: {
options: {
some: {
title: 'square',
description: '20',
},
some: {
title: 'type',
description: 'invertor',
},
},
},
include: { options: true },
});
I separated the some filters for each condition. This should retrieve products that have at least one option with the first set of conditions (title: 'square', description: '20') and at least one option with the second set of conditions (title: 'type', description: 'invertor').