PrismaP
Prisma13mo ago
3 replies
Brokenwind

Prisma.skip on deeply nested objects

Hello, is there a way to Prisma.skip deeply nested objects?

In this case:

  const {
    _sum: { netSales = 0 },
  } = await prisma.returnsItem.aggregate({
    where: {
      inventory: {
        product: {
          categoryId: productCategoryId ?? Prisma.skip,
        },
      },
      returns: {
        transactionDate: {
          gte: start.toDate(),
          lte: end.toDate(),
        },
        salesChannelId: salesChannelId ?? Prisma.skip,
        territory: {
          id: territoryId ?? Prisma.skip,
          district: {
            id: districtId ?? Prisma.skip,
            region: {
              id: regionId ?? Prisma.skip,
            },
          },
        },
      },
    },
    _sum: {
      netSales: true,
    },
  });


When territoryId, districtId, and regionId are all undefined, it gives out this as a result:

territory: { id: dr {}, district: { id: dr {}, region: { id: dr {}, } } }


Normally I would expect it to not consider the territory clause at all since all of it are skipped. For some reason, prisma doesn't skip this and returns null.
Was this page helpful?