Hi All,
I’m having an issue doing nested writes on a one-to-many relationship. I’m unsure if this is a RW issue, Prisma issue, or just a ME issue.
I have some models (only including most relevant below
model Pass {
id Int @id @default(autoincrement())
user User? @relation(fields: [userId], references: [id])
userId String?
purchasedAt DateTime? @default(now())
product Product @relation(fields: [productId], references: [id])
productId Int
agentReference String @default("")
transactions Transaction[]
status passStatus @default(value: PENDING)
notes String?
nights Int @default(0)
price Int @default(0)
company Company? @relation(fields: [companyId], references: [id])
companyId Int?
customerName String? @default("")
}
model User {
id String @id @default(cuid())
email String @unique
hashedPassword String? @default("")
salt String? @default("")
resetToken String?
resetTokenExpiresAt DateTime?
company Company? @relation(fields: [companyId], references: [id])
companyId Int? @unique
transactions Transaction[]
passes Pass[]
fullName String?
cardIssuedby String?
roles Role[]
}
I’m trying to do a nested update that looks like this
return db.pass.create({
data: {
..... other data.......,
user: {
connectOrCreate: {
where: { input.email },
create: { input.email, fullName: input. customerName },
},
},
})}
When i do this I get an error
Unknown arg `user` in data.user for type PassUncheckedCreateInput. Did you mean `userId`? Available args:
api | type PassUncheckedCreateInput {
api | id?: Int
api | userId?: String | Null
api | purchasedAt?: DateTime | Null
api | productId: Int
api | agentReference?: String
api | transactions?: TransactionUncheckedCreateNestedManyWithoutPassInput
api | status?: passStatus
api | notes?: String | Null
api | nights?: Int
api | price?: Int
api | companyId?: Int | Null
api | customerName?: String | Null
api | }
When I dig into the prisma client inputs is see:
export type PassCreateInput = {
user?: UserCreateNestedOneWithoutPassesInput
purchasedAt?: Date | string | null
product: ProductCreateNestedOneWithoutPassesInput
agentReference?: string
transactions?: TransactionCreateNestedManyWithoutPassInput
status?: passStatus
notes?: string | null
nights?: number
price?: number
company?: CompanyCreateNestedOneWithoutPassesInput
customerName?: string | null
}
export type PassUncheckedCreateInput = {
id?: number
userId?: string | null
purchasedAt?: Date | string | null
productId: number
agentReference?: string
transactions?: TransactionUncheckedCreateNestedManyWithoutPassInput
status?: passStatus
notes?: string | null
nights?: number
price?: number
companyId?: number | null
customerName?: string | null
}
So after all that, my question is. Why can I not perform this nested update? Am i missing something, Is something not being generated correctly?
I can perform other nested queries on createPass. Like:
transactions: {
create: [
{
nights: input.nights,
transactionType: `PURCHASE`,
value: input.price,
userId: 'cl7bdq9f50040718y85x8fqb9',
staffMember: 'Shannon Hardcode',
companyId: input.companyId,
},
],
},
Any help is appreciated. Thanks