PrismaP
Prisma2y ago
9 replies
ncls.

How to reference/store a joined primary key?

I have a program that imports data from a CSV file into the database using Prisma. In the Excel the rows have something similar to an ID, a category and other non-important stuff. Since the ID is not unique in this CSV, I created a joined primary key in my schema file (@@id([category, id])).

Is there any way I can reference this joined primary key in a relation?

E.g.:
model FirstEntity {
  id        Int
  category  String
  relations Relation[]

  @@id([category, id])
}

model Relation {
  id         Int         @id @default(autoincrement())
  relationId String
  relation   FirstEntity @relation(fields: [relatesToId], references: [category, id])
}
Was this page helpful?