Using Prisma 4.15, NestJS 10.0.2, PostgreSQL 14
I am trying to retrieve many entities named transmission
, filtering them by the patientId
and isDraft
properties, and including the patient
and constants
entities related to them, with a pager.
async findByPatient(patientId: string, page: number = 1, perPage: number = 2) {
const transmissions = await this.prisma.transmission.findMany({
where: {
patientId,
isDraft: false,
},
include: {
patient: true,
constants: true,
},
orderBy: {
createdAt: 'desc',
},
take: perPage,
skip: (page - 1) * perPage,
});
return transmissions;
}
When firing the endpoint that calls this function, it failed to filter on the patientId
in the where
bloc, and only took the isDraft: false
into account when watching the results.
My intuition is that the include block somehow interferes with the filtering as I'm including patients
in my results.
I have already tried explicitly using patientId: { equals: patientId }
instead of just patientId
in the where
bloc, to no avail, the results didn't change at all.
Other queries that do not filter using patientId
but include patient
and constants
are working flawlessly.
No other query that filters using one of the included entities are in use right now.
Any workaround to make this query work?
So, the prisma call works fine, the problem was with my controller where I wrote @Param(:patientId')
instead of @Param('patientId')
so the patientId sent to that function was undefined