Theo's Typesafe CultTTC
Theo's Typesafe Cult3y ago
7 replies
utdev

Help defining Prisma schema

Hi guys I need some help defining my prisma schema.

I have this template schema in which I would like to add tags:
model Template {
  id          String        @id @default(cuid())
  name        String
  description String?
  visibility  String        @default("private")
  filename    String
  content     String
  createdAt   DateTime      @default(now())
  updatedAt   DateTime      @updatedAt
  user        User          @relation(fields: [userId], references: [id], onDelete: Cascade)
  userId      String
  tags        TemplateTag[]
}


So I added the tags field and created a relation to this TemplateTag model:

model TemplateTag {
  id         String    @id @default(cuid())
  tag        String
  Template   Template[]
  templateId String?
}


But since the same tag can be used in a different Template, this does not make much sense I think, it would cause redundant data.
How do I create a proper pivot table or should I do this differently?
Was this page helpful?