I'm trying to perform an update operation:
const specialItem = await db.specialItem.update({ where: query, data: formattedUpdate })
The value formattedUpdate
in that statement looks something like this:
{
item_name: null,
drink_type: 'Wine',
price: 800,
bar: {
connect: {
id: '4486bbc3-5ff8-47c8-99cf-9291c57ebe78'
}
},
event: {
connect: {
id: undefined
}
},
related_item: {
connect: {
id: undefined
}
}
}
This operation fails in the Prisma validator with the errors:
[1] Unknown arg `bar` in data.bar for type SpecialItemUncheckedUpdateInput. Did you mean `id`? Available args: ...
[1] Unknown arg `event` in data.event for type SpecialItemUncheckedUpdateInput. Did you mean `event_id`? Available args: ...
[1] Unknown arg `related_item` in data.related_item for type SpecialItemUncheckedUpdateInput. Did you mean `related_item_id`? Available args: ...
However those fields are most definitely in my schema:
model SpecialItem {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
created_at DateTime @default(now()) @db.Timestamptz(3)
event Event? @relation(fields: [event_id], references: [id], onDelete: Cascade)
event_id String? @db.Uuid
bar Bar @relation(fields: [bar_id], references: [id], onDelete: Cascade)
bar_id String @db.Uuid
related_item_id String? @db.Uuid
related_item Item? @relation(fields: [related_item_id], references: [id])
is_recurring Boolean @default(false)
is_inactive Boolean @default(false)
...
}
The available args the error suggests comes from the generated Prisma type ModelNameUncheckedUpdateInput
, however I believe this operation would succeed if it were using the generated Prisma type ModelNameUpdateInput
. The unchecked version uses IDs directly, where as the regular version uses the connect object pattern. I'd prefer using the latter. Why is Prisma expecting me to satisfy the unchecked version of the type? Can I force the validator to use the regular version?
Has anyone run into this before? I don't think it makes sense to break from the connect pattern I use elsewhere.
Using Prisma version 4.9.0.
I've tried searching, ChatGPT, the github, read the docs, and no cigar.
Could you modify your code to get this result:
{
item_name: null,
drink_type: 'Wine',
price: 800,
bar: {
connect: {
id: '4486bbc3-5ff8-47c8-99cf-9291c57ebe78'
}
}
}
I'm not sure, but look like Prisma will use Unchecked
type if there are undefined
in nested fields
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.