P
Prisma•3mo ago
Arthur

Upsert by Reference ID

Hello, I'm trying to upsert data by reference ID but Prisma reject this action Execution Code
this.prismaService.securityCheque.upsert({
where: {
loan_id: payload.loanId,
},
create: {
...
},
update: {
...
},
});
this.prismaService.securityCheque.upsert({
where: {
loan_id: payload.loanId,
},
create: {
...
},
update: {
...
},
});
Error
Type '{ loan_id: number; }' is not assignable to type 'SecurityChequeWhereUniqueInput'.
Type '{ loan_id: number; }' is not assignable to type 'SecurityChequeWhereUniqueInput'.
Schema
model Loan {
id Int @id @default(autoincrement())
...
created_at DateTime @default(now())
updated_at DateTime @default(now()) @updatedAt

// Relations
security_cheques SecurityCheque[]

@@map("loans")
}

model SecurityCheque {
id Int @id @default(autoincrement())
...
created_at DateTime @default(now())
updated_at DateTime @default(now()) @updatedAt

// Relations
loan Loan @relation(fields: [loan_id], references: [id])

@@map("security_cheques")
}
model Loan {
id Int @id @default(autoincrement())
...
created_at DateTime @default(now())
updated_at DateTime @default(now()) @updatedAt

// Relations
security_cheques SecurityCheque[]

@@map("loans")
}

model SecurityCheque {
id Int @id @default(autoincrement())
...
created_at DateTime @default(now())
updated_at DateTime @default(now()) @updatedAt

// Relations
loan Loan @relation(fields: [loan_id], references: [id])

@@map("security_cheques")
}
5 Replies
Nurul
Nurul•3mo ago
Prisma needs to uniquely identify the record that needs to be created or updated, which is why the field that you pass in the where clause needs to be uniquely identifiable. In your case just filtering by loan_id would not ensure that only a unique record would be obtained.
Arthur
Arthur•3mo ago
@Nurul (Prisma) So basically the issue is, that loan_id is not unique. Do I understand correctly?
Nurul
Nurul•3mo ago
Exactly! That's the issue.
Arthur
Arthur•3mo ago
Thx!
Nurul
Nurul•3mo ago
No worries! 😄
Want results from more Discord servers?
Add your server