P
Prisma•5d ago
b0ngl0rd

Argument `where` of type *WhereUniqueInput needs at least one of `id` arguments.

No TS or linting warnings, and yet I am running into a problem with a simple update query. Relevant query:
ctx.db.table.update({
where: {
id: table.id,
},
data: {
relief: {
disconnect: true,
},
dealer: {
connect: table.relief ? { id: table.relief.id } : undefined,
},
dealerStartTime: new Date(),
},
}),
ctx.db.table.update({
where: {
id: table.id,
},
data: {
relief: {
disconnect: true,
},
dealer: {
connect: table.relief ? { id: table.relief.id } : undefined,
},
dealerStartTime: new Date(),
},
}),
Log of input provided to query before calling it:
[ { id: 57, relief: { id: 201 }, dealer: null } ]
[ { id: 57, relief: { id: 201 }, dealer: null } ]
Log of error:
PrismaClientValidationError:
Invalid `prisma.table.update()` invocation:

{
where: {
id: 57,
? AND?: DealerWhereInput | DealerWhereInput[],
? OR?: DealerWhereInput[],
? NOT?: DealerWhereInput | DealerWhereInput[],
? name?: StringFilter | String,
? startTime?: DateTimeFilter | DateTime,
? breakStartTime?: DateTimeNullableFilter | DateTime | Null,
? gamesKnown?: GameListRelationFilter,
? table?: TableNullableRelationFilter | TableWhereInput | Null,
? goingTo?: TableNullableRelationFilter | TableWhereInput | Null
},
data: {
relief: {
disconnect: true
},
dealer: {
connect: {
id: 201
}
},
dealerStartTime: new Date("2024-10-17T21:08:47.547Z")
}
}

Argument `where` of type DealerWhereUniqueInput needs at least one of `id` arguments. Available options are marked with ?.
PrismaClientValidationError:
Invalid `prisma.table.update()` invocation:

{
where: {
id: 57,
? AND?: DealerWhereInput | DealerWhereInput[],
? OR?: DealerWhereInput[],
? NOT?: DealerWhereInput | DealerWhereInput[],
? name?: StringFilter | String,
? startTime?: DateTimeFilter | DateTime,
? breakStartTime?: DateTimeNullableFilter | DateTime | Null,
? gamesKnown?: GameListRelationFilter,
? table?: TableNullableRelationFilter | TableWhereInput | Null,
? goingTo?: TableNullableRelationFilter | TableWhereInput | Null
},
data: {
relief: {
disconnect: true
},
dealer: {
connect: {
id: 201
}
},
dealerStartTime: new Date("2024-10-17T21:08:47.547Z")
}
}

Argument `where` of type DealerWhereUniqueInput needs at least one of `id` arguments. Available options are marked with ?.
Even inside the error thrown, it is apparent that an id is indeed being passed. I'm not sure where to go from here, it seems very simple so maybe I'm missing something?
Solution:
after digging on how to enable debug logs for prisma, i found out that it was another query responsible.
Jump to solution
7 Replies
b0ngl0rd
b0ngl0rd•5d ago
just in case this is helpful
No description
Nurul
Nurul•5d ago
Hey @b0ngl0rd 👋 What is the value of table variable here?
where: {
id: table.id,
},
where: {
id: table.id,
},
Is the value of table this: [ { id: 57, relief: { id: 201 }, dealer: null } ]?
b0ngl0rd
b0ngl0rd•4d ago
It's the object inside that array, yes. In the bigger picture, this is a piece of a transaction, hence the array. However, the error points to this exact query.
Nurul
Nurul•4d ago
Can you share the dealer model?
b0ngl0rd
b0ngl0rd•4d ago
model Dealer {
id Int @id @default(autoincrement())
name String
gamesKnown Game[]
startTime DateTime
breakStartTime DateTime?
table Table? @relation("dealer")
goingTo Table? @relation("relief")
}
model Dealer {
id Int @id @default(autoincrement())
name String
gamesKnown Game[]
startTime DateTime
breakStartTime DateTime?
table Table? @relation("dealer")
goingTo Table? @relation("relief")
}
model Table {
id Int @id @default(autoincrement())
tableNum Int
game Game @relation(fields: [gameId], references: [id])
gameId Int
dealer Dealer? @relation("dealer", fields: [dealerId], references: [id])
dealerId Int? @unique
dealerStartTime DateTime?
relief Dealer? @relation("relief", fields: [reliefId], references: [id])
reliefId Int? @unique
}
model Table {
id Int @id @default(autoincrement())
tableNum Int
game Game @relation(fields: [gameId], references: [id])
gameId Int
dealer Dealer? @relation("dealer", fields: [dealerId], references: [id])
dealerId Int? @unique
dealerStartTime DateTime?
relief Dealer? @relation("relief", fields: [reliefId], references: [id])
reliefId Int? @unique
}
so it turns out that prisma won't always return the correct query responsible for throwing an error when processing a transaction.
Solution
b0ngl0rd
b0ngl0rd•4d ago
after digging on how to enable debug logs for prisma, i found out that it was another query responsible.
b0ngl0rd
b0ngl0rd•4d ago
prisma:client prisma.dealer.update({
where: {
id: undefined
},
data: {
breakStartTime: new Date("2024-10-18T21:00:01.763Z"),
table: {
disconnect: true
}
}
})
prisma:client prisma.dealer.update({
where: {
id: undefined
},
data: {
breakStartTime: new Date("2024-10-18T21:00:01.763Z"),
table: {
disconnect: true
}
}
})
is the cause. so this is because i misunderstood the docs or something on how to make a query optional. looks like prisma only reports the first in the batch as the problem, when it could be any of them.
Want results from more Discord servers?
Add your server