So I have a prisma schema with user and data that has an array
type AkPastRecruitment {
date Int
tags String[]
picked String[]
outcome String?
time Float
}
type AkHistory {
recruitments AkPastRecruitment[]
}
model akdata {
id String @id @default(auto()) @map("_id") @db.ObjectId
history AkHistory?
// relations
dataRelation users? @relation("dR", fields: [id], references: [dataId])
}
model users {
id String @id @default(auto()) @map("_id") @db.ObjectId
username String @unique
pass String @default("password") @map("_q")
dataId String? @unique @db.ObjectId
//relations
dR akdata? @relation("dR")
}
Whenever I try to update it via relation it errors out
The update
/* type of data.history:
{
date: number;
tags: string[];
picked: string[];
outcome: string | null;
time: number;
}[] | undefined
*/
const recruitments:
| Prisma.Enumerable<Prisma.AkPastRecruitmentCreateInput>
| undefined = data.history ? [...data.history] : data.history;
const history: Prisma.AkHistoryCreateInput | null = data.history
? {
recruitments,
}
: null;
await prismaClient.users.update({
where: { username: data.username },
data: {
dR: {
update: {
history
},
},
},
});
But it throws error:
Unknown arg `recruitments` in data.dR.update.history.recruitments for type AkHistoryNullableUpdateEnvelopeInput. Available args:
type AkHistoryNullableUpdateEnvelopeInput {
set?: AkHistoryCreateInput | Null
upsert?: AkHistoryUpsertInput
unset?: Boolean
}
But when I change it into AkHistoryNullableUpdateEnvelopeInput
const recruitments:
| Prisma.Enumerable<Prisma.AkPastRecruitmentCreateInput>
| undefined = data.history ? [...data.history] : data.history;
const history: Prisma.AkHistoryNullableUpdateEnvelopeInput | null =
data.history
? {
set: {
recruitments,
},
}
: null;
await prismaClient.users.update({
where: { username: data.username },
data: {
dR: {
update: {
history
},
},
},
});
It throws an error that tells me to go back to the previous way with AkHistoryCreate
Unknown arg `set` in data.dR.update.history.set for type AkHistoryCreateInput. Did you mean `select`? Available args:
type AkHistoryCreateInput {
recruitments?: AkPastRecruitmentCreateInput | List<AkPastRecruitmentCreateInput>
}
How do you update an array inside the relation in prisma?
I was searching the docs but couldn’t find it anywhere and these errors don’t help at all.