Relationship issue
Hey, I'm probably being super duper stupid here, but I am new to Prisma and I'm missing something.
I have the schema:
I then have a JS function that reads in a JSON object, and tries to save it to the DB (shortened for brevity):
I get the repetitive error of:
I have the schema:
model Ticket {
id BigInt @id
description String @db.LongText
descriptionHtml String @map("description_html") @db.LongText
subject String @db.LongText
displayId Int @map("display_id")
ticketType String? @map("ticket_type")
status Int
priority Int
urgent Boolean
spam Boolean
deleted Boolean
source Int
trained Boolean
createdAt DateTime @map("created_at")
updatedAt DateTime @map("updated_at")
dueBy DateTime? @map("due_by")
frDueBy DateTime? @map("frDueBy")
isEscalated Boolean @map("isescalated")
frEscalated Boolean @map("fr_escalated")
groupId BigInt?
ownerId BigInt?
requesterId BigInt?
responderId BigInt?
accountId Int
slaState Int @default(0)
delta Boolean
dirty Int
customField Json? @map("custom_field")
ccEmail Json? @map("cc_email")
tags Json?
attachments Json?
statusName String? @map("status_name")
requesterStatusName String? @map("requester_status_name")
priorityName String? @map("priority_name")
sourceName String? @map("source_name")
productId BigInt? @map("product_id")
toEmails Json?
reportsData Json? @map("reports_data")
ticketStates Json? @map("ticket_states")
// Relations
requester User? @relation("RequestedBy", fields: [requesterId], references: [id])
responder User? @relation("RespondedBy", fields: [responderId], references: [id])
group Group? @relation(fields: [groupId], references: [id])
owner Company? @relation("OwnedBy", fields: [ownerId], references: [id])
Note Note[]
}model Ticket {
id BigInt @id
description String @db.LongText
descriptionHtml String @map("description_html") @db.LongText
subject String @db.LongText
displayId Int @map("display_id")
ticketType String? @map("ticket_type")
status Int
priority Int
urgent Boolean
spam Boolean
deleted Boolean
source Int
trained Boolean
createdAt DateTime @map("created_at")
updatedAt DateTime @map("updated_at")
dueBy DateTime? @map("due_by")
frDueBy DateTime? @map("frDueBy")
isEscalated Boolean @map("isescalated")
frEscalated Boolean @map("fr_escalated")
groupId BigInt?
ownerId BigInt?
requesterId BigInt?
responderId BigInt?
accountId Int
slaState Int @default(0)
delta Boolean
dirty Int
customField Json? @map("custom_field")
ccEmail Json? @map("cc_email")
tags Json?
attachments Json?
statusName String? @map("status_name")
requesterStatusName String? @map("requester_status_name")
priorityName String? @map("priority_name")
sourceName String? @map("source_name")
productId BigInt? @map("product_id")
toEmails Json?
reportsData Json? @map("reports_data")
ticketStates Json? @map("ticket_states")
// Relations
requester User? @relation("RequestedBy", fields: [requesterId], references: [id])
responder User? @relation("RespondedBy", fields: [responderId], references: [id])
group Group? @relation(fields: [groupId], references: [id])
owner Company? @relation("OwnedBy", fields: [ownerId], references: [id])
Note Note[]
}I then have a JS function that reads in a JSON object, and tries to save it to the DB (shortened for brevity):
function toCamelCaseTicket(ticket: any) {
return {
id: BigInt(ticket.id),
requester: ticket.requester_id
? {
connect: { id: BigInt(ticket.requester_id) },
}
: null,
responder: ticket.responder_id
? {
connect: { id: BigInt(ticket.responder_id) },
}
: null,
group: ticket.group_id
? {
connect: { id: BigInt(ticket.group_id) },
}
: null,
owner: ticket.owner_id
? {
connect: { id: BigInt(ticket.owner_id) },
}
: null,
};
}
async function insertTickets(data: any[]) {
for (const entry of data) {
const mapped = toCamelCaseTicket(entry.helpdesk_ticket)
console.log("Mapped", JSON.stringify(mapped, (_, v) => typeof v === 'bigint' ? v.toString() : v));
await prisma.ticket.upsert({
where: { id: BigInt(mapped.id) },
update: {},
create: mapped,
})
}
}function toCamelCaseTicket(ticket: any) {
return {
id: BigInt(ticket.id),
requester: ticket.requester_id
? {
connect: { id: BigInt(ticket.requester_id) },
}
: null,
responder: ticket.responder_id
? {
connect: { id: BigInt(ticket.responder_id) },
}
: null,
group: ticket.group_id
? {
connect: { id: BigInt(ticket.group_id) },
}
: null,
owner: ticket.owner_id
? {
connect: { id: BigInt(ticket.owner_id) },
}
: null,
};
}
async function insertTickets(data: any[]) {
for (const entry of data) {
const mapped = toCamelCaseTicket(entry.helpdesk_ticket)
console.log("Mapped", JSON.stringify(mapped, (_, v) => typeof v === 'bigint' ? v.toString() : v));
await prisma.ticket.upsert({
where: { id: BigInt(mapped.id) },
update: {},
create: mapped,
})
}
}I get the repetitive error of:
Unknown argument requester. Did you mean requesterId? Available options are marked with ?.
at An (node_modules/@prisma/client/runtime/library.js:29:1363)
at zn.handleRequestError (node_modules/@prisma/client/runtime/library.js:121:7102)
at zn.handleAndLogRequestError (node_modules/@prisma/client/runtime/library.js:121:6784)
at zn.request (node_modules/@prisma/client/runtime/library.js:121:6491)
at async l (node_modules/@prisma/client/runtime/library.js:130:9778)
at async insertTickets (server/api/import.post.ts:135:1)
at async <anonymous> (server/api/import.post.ts:69:1)Unknown argument requester. Did you mean requesterId? Available options are marked with ?.
at An (node_modules/@prisma/client/runtime/library.js:29:1363)
at zn.handleRequestError (node_modules/@prisma/client/runtime/library.js:121:7102)
at zn.handleAndLogRequestError (node_modules/@prisma/client/runtime/library.js:121:6784)
at zn.request (node_modules/@prisma/client/runtime/library.js:121:6491)
at async l (node_modules/@prisma/client/runtime/library.js:130:9778)
at async insertTickets (server/api/import.post.ts:135:1)
at async <anonymous> (server/api/import.post.ts:69:1)