Moymat
Moymat
Explore posts from servers
PPrisma
Created by Moymat on 5/30/2024 in #help-and-questions
Prisma ORM returns two different results from two similar (?) queries
Hi everyone ! Could someone help me figure out why this two queries don't return the same result ? As I understand, the values given to is_deleted, type and inserted should be mandatory for both queries, but it seems that only the second one, with the duplicated common fields in both OR 'branches', give me the correct result.
// Returns only one row
await this.prisma.alert.findMany({
where: {
is_deleted: withDeleted ? undefined : false,
type: alertType === 'all' ? undefined : alertType,
inserted: {
gte: startDate,
lt: endDate,
},
OR: [
{
group_id: {
in: groupIds,
},
},
{
groups: {
some: {
group_id: {
in: groupIds,
},
},
},
},
],
}
});

// Returns 10 rows as intended
await this.prisma.alert.findMany({
where: {
OR: [
{
is_deleted: withDeleted ? undefined : false,
type: alertType === 'all' ? undefined : alertType,
inserted: {
gte: startDate,
lt: endDate,
},
group_id: {
in: groupIds,
},
},
{
is_deleted: withDeleted ? undefined : false,
type: alertType === 'all' ? undefined : alertType,
inserted: {
gte: startDate,
lt: endDate,
},
groups: {
some: {
group_id: {
in: groupIds,
},
},
},
},
],
}
});
// Returns only one row
await this.prisma.alert.findMany({
where: {
is_deleted: withDeleted ? undefined : false,
type: alertType === 'all' ? undefined : alertType,
inserted: {
gte: startDate,
lt: endDate,
},
OR: [
{
group_id: {
in: groupIds,
},
},
{
groups: {
some: {
group_id: {
in: groupIds,
},
},
},
},
],
}
});

// Returns 10 rows as intended
await this.prisma.alert.findMany({
where: {
OR: [
{
is_deleted: withDeleted ? undefined : false,
type: alertType === 'all' ? undefined : alertType,
inserted: {
gte: startDate,
lt: endDate,
},
group_id: {
in: groupIds,
},
},
{
is_deleted: withDeleted ? undefined : false,
type: alertType === 'all' ? undefined : alertType,
inserted: {
gte: startDate,
lt: endDate,
},
groups: {
some: {
group_id: {
in: groupIds,
},
},
},
},
],
}
});
4 replies