Recently I updated prisma from 2.7.0 to 2.19.0, I made the respectively changes (findOne to findUnique mainly) but this one refuses to work:
const eventFilter = { AND: [
{ startTime: { lte: moment().toISOString() } },
{ endTime: { gte: moment().toISOString() } },
{ place:{ id: placeId || { not: null } } }
] }
await prisma.eventParticipant.findMany({
where: {
user: { id: XXX },
event: eventFilter
}
})
But doing this throws this error (short version hehe): Unknown arg `AND` in where.event.AND for type EventRelationFilter
So I looked for the type of findMany(...)
argument at index.d.ts
(at node_modules/.prisma/client) and I've found:
findMany<T extends EventParticipantFindManyArgs>(
args?: SelectSubset<T, EventParticipantFindManyArgs>
): CheckSelect<T, PrismaPromise<Array<EventParticipant>>, PrismaPromise<Array<EventParticipantGetPayload<T>>>>
Then I looked for what EventParticipantFindManyArgs
has:
export type EventParticipantFindManyArgs {
// Has another props but this one is that interest
where?: EventParticipantWhereInput
}
And again... Looked for what EventParticipantWhereInput
has:
export type EventParticipatnWhereInput {
// Like before, this one has another props but this one is that interest
event?: XOR<EventRelationFilter, EventWhereInput> | null
}
At this point i expected that eventFilter
(my const) fits in EventParticipatnWhereInput.event
type
And finally I looked for EventRelationFilter
and it has:
export type EventRelationFilter = {
is?: EventWhereInput | null
isNot?: EventWhereInput | null
}
Aaand EventWhereInput
has all props that eventFilter
has
So... when i saw it i said: "Why my eventFilter
object doesn't fit as EventWhereInput
?"
I've tried to fix this doing:
import { Prisma } from '@prisma/client' // Import types from exported namespace called "Prisma"
// This one doesn't throw error like "{...} is not assignable to object of type Prisma.EventWhereInput
// So I assume this is fine
const eventFilter: Prisma.EventWhereInput = { AND: [
{ startTime: { lte: moment().toISOString() } },
{ endTime: { gte: moment().toISOString() } },
{ place:{ id: placeId || { not: null } } }
] }
But, doing this changes nothing. same error like before (prisma expects where.event to be "EventRelationFilter" type)
So I said "Ok u fking prisma, I'll make eventFilter
"EventRelationFilter" type:
import { Prisma } from '@prisma/client' // Import types from exported namespace called "Prisma"
// This one doesn't throw error like "{...} is not assignable to object of type Prisma.EventRelationFilter
// So I assume this is fine too
const eventFilter: Prisma.EventRelationFilter = { is: { AND: [
{ startTime: { lte: moment().toISOString() } },
{ endTime: { gte: moment().toISOString() } },
{ place:{ id: placeId || { not: null } } }
] } }
But (and my hopes are gone to stackoverflow from this point) throw this error: Unknown arg `is` in where.event.is for type EventWhereInput
And i said: "What?? both are errors? whats does prisma wants from me?"
Sorry, my question is quite long but im very confused about this.
BTW: eventParticipants is the "join table" between user and event I'm not sure
EDIT: Schema:
model Event {
id Int @id @default(autoincrement())
name String
description String?
// ...
participantUsers EventParticipant[]
}
model User {
id Int @id @default(autoincrement())
name String
alias String? @unique @default(dbgenerated())
birthDay DateTime? @map("dateOfBirth")
// ...
event Event[]
@@map(name: "user")
}
model EventParticipant {
id Int @id @default(autoincrement())
event_id Int?
user_id Int?
event Event? @relation(fields: [event_id], references: [id])
user User? @relation("event_participants_idToUser", fields: [user_id], references: [id])
@@map(name: "event_participants")
}
Thanks!
Sorry, my mistake... place: { id: { not: null } }
"not" expects to have a NestedIntFilter
or number
, so null
is a invalid value for that key
const eventFilter: Prisma.EventWhereInput = { AND: [
{ startTime: { lte: moment().toISOString() } },
{ endTime: { gte: moment().toISOString() } },
// WRONG { place:{ id: placeId || { not: null } } }
{ place:{ id: placeId } } // FINE!
] }
Need to fix that validation in another way.. it's strange the fact that my IDE doesn't throw an error like {...} is not assignable to Prisma.EventWhereInput
or something like that.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.