how to filter null property inside where?
# orm-help
g
how to filter null property inside where?
r
where: { field: null }
❤️ 1
g
@Ryan how about if the field is a relation to other schema?
r
Can you share the model and relation?
g
Solved it!! prisma type safety is awesome. OR: [ { workType: { type: { equals: 'On site', }, }, }, { workTypeId: null, }, ]
prisma cool 1
🙌 1
can't reuse where object
Type '{ visitorId: { readonly equals: number; }; siteId: { readonly equals: number; }; OR: readonly [{ readonly workType: { readonly type: { readonly equals: "On site"; }; }; }, { readonly workTypeId: any; }]; dateCreated: { ...; }; timeCreated: { ...; }; }' is not assignable to type 'VisitWhereInput'. Types of property 'OR' are incompatible. Type 'readonly [{ readonly workType: { readonly type: { readonly equals: "On site"; }; }; }, { readonly workTypeId: any; }]' is not assignable to type 'Enumerable<VisitWhereInput>'. The type 'readonly [{ readonly workType: { readonly type: { readonly equals: "On site"; }; }; }, { readonly workTypeId: any; }]' is 'readonly' and cannot be assigned to the mutable type 'VisitWhereInput[]'.
@Ryan
r
Could you try removing
as const
and check?
❤️ 1
g
@Ryan thank you ryan 🙂 big help!
Is there a feature in prisma where we can rename field property? eg: select floor as 'siteFloor'
r
Not yet, but it would be great if you could add a 👍 to this feature request and follow for more updates: https://github.com/prisma/prisma/issues/4433
❤️ 1
h
@Ryan Hello, I'm trying to do this same thing but I can't re-use my where object. Any help would be awesome!
Type '{ uid: string; status: string | { in: string[]; }; subType: { in: any; }; type: { in: any; }; price: { gte: any; lte: any; }; OR: ({ subject: { contains: any; mode: string; }; marketing?: undefined; province?: undefined; ... 5 more ...; User?: undefined; } | ... 9 more ... | { ...; })[]; timeStamp: { ...; }; User: {...' is not assignable to type 'ListingWhereInput'.
Types of property 'OR' are incompatible.
Type '({ subject: { contains: any; mode: string; }; marketing?: undefined; province?: undefined; city?: undefined; postal?: undefined; subType?: undefined; type?: undefined; address?: undefined; User?: undefined; } | ... 9 more ... | { ...; })[]' is not assignable to type 'Enumerable<ListingWhereInput>'.
Type '({ subject: { contains: any; mode: string; }; marketing?: undefined; province?: undefined; city?: undefined; postal?: undefined; subType?: undefined; type?: undefined; address?: undefined; User?: undefined; } | ... 9 more ... | { ...; })[]' is not assignable to type 'ListingWhereInput[]'.ts(2322)
index.d.ts(2064, 5): The expected type comes from property 'where' which is declared here on type '{ select?: ListingSelect; include?: ListingInclude; where?: ListingWhereInput; orderBy?: Enumerable<ListingOrderByInput>; cursor?: ListingWhereUniqueInput; take?: number; skip?: number; distinct?: Enumerable<...>; }'
r
@Harjaap Singh Makkar Try adding the type to
where
and see where the error is in your object:
Copy code
const where: Prisma.ListingWhereInput = {}
And check if your object matches the
where
condition properly.
h
Thank you, Ryan. For 'Prisma.' am I using the prisma object imported from the image attached? (I'm in nextjs). Because in this case it says "Cannot find namespace 'Prisma' even though I'm using prisma for all the other queries in this file as shared in the photo shared earlier
Nevermind, I got it, had to import { Prisma } from PrismaClient 🙂
💯 1