Arthur
Arthur
PPrisma
Created by Arthur on 9/10/2024 in #help-and-questions
Return Type With Relations
Hello there, I have a quick question about return type with relation. If I have this sort of query:
this.prismaService.loan.findFirst({
where,
include: {
customer: true
},
});
this.prismaService.loan.findFirst({
where,
include: {
customer: true
},
});
So should Prisma's type have a customer as a return type?
import { Loan } from '@prisma/client';
import { Loan } from '@prisma/client';
If it is, why does it always crying that the customer is not a part of the type of loan?
7 replies
PPrisma
Created by Arthur on 7/29/2024 in #help-and-questions
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")
}
7 replies