Prisma.skip on deeply nested objects
Hello, is there a way to Prisma.skip deeply nested objects?
In this case:
When territoryId, districtId, and regionId are all undefined, it gives out this as a result:
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.
3 Replies
You selected the carefully hand-crafted route. A dev artisan will respond soon. Meanwhile, the
#ask-ai
channel awaits if you're curious!Hey 👋
Can you please elaborate?
What output are you currently getting and what output were you expecting?
Hey, thanks for responding.
In my specific example:
I have this structure in place so I can supply the territoryId, districtId, regionId when filtering. This allows me to have dynamic filtering and I want to supply these as needed.
Just giving them territoryId, districtId, or regionId works in itself and filters through that. My issue is when I have those 3 undefined. It will use Prisma.skip as intended but it doesn't give me the result I want.
The result that I want is to not filter any by territory at all. Instead, prisma (I believe) is filtering where territories are undefined (which shouldn't because I have strictUndefinedChecks) and I get no result.
When I log the filters, this is what it looks like:
territory: { id: dr {}, district: { id: dr {}, region: { id: dr {}, } } }
Which is what prisma does when all three are undefined.
Currently, this works for me:
In my opinion, if this is the structure:
It should just skip it. My workaround is ugly code and I wish I didn't need that.