P
Prisma•4mo 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•4mo 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
ArthurOP•4mo ago
@Nurul (Prisma) So basically the issue is, that loan_id is not unique. Do I understand correctly?
Nurul
Nurul•4mo ago
Exactly! That's the issue.
Arthur
ArthurOP•4mo ago
Thx!
Nurul
Nurul•4mo ago
No worries! 😄
Want results from more Discord servers?
Add your server