PrismaP
Prisma2y ago
FM-96

Strange @relation fields in auto-generated models

Using
prisma@5.13.0
, I ran
npx prisma db pull
to generate models for an existing SQLite database.

It generated these models:
model chapters {
  id        Int     @id @default(autoincrement())
  story     Int
  chapter   Float
  name      String?
  published Boolean @default(true)
  read      Boolean @default(false)
  rereading Boolean @default(false)
  stories   stories @relation(fields: [story], references: [id], onDelete: NoAction, onUpdate: NoAction)
}

model fandoms {
  id      Int       @id @default(autoincrement())
  name    String    @unique(map: "sqlite_autoindex_fandoms_1")
  series  series[]
  stories stories[]
}

model series {
  id                             Int       @id @default(autoincrement())
  name                           String    @unique(map: "sqlite_autoindex_series_1")
  fandom                         Int
  fandoms                        fandoms   @relation(fields: [fandom], references: [id], onDelete: NoAction, onUpdate: NoAction)
  stories_stories_seriesToseries stories[] @relation("stories_seriesToseries")
}

model stories {
  id                            Int        @id @default(autoincrement())
  series                        Int?
  number                        Float
  name                          String
  fandom                        Int?
  status                        String?
  link                          String?
  chapters                      chapters[]
  fandoms                       fandoms?   @relation(fields: [fandom], references: [id], onDelete: NoAction, onUpdate: NoAction)
  series_stories_seriesToseries series?    @relation("stories_seriesToseries", fields: [series], references: [id], onDelete: NoAction, onUpdate: NoAction)
}

I do not understand the
stories_stories_seriesToseries
and
series_stories_seriesToseries
fields. What are these cryptic names? And why do the
@relation
attributes have a
name
argument? Shouldn't they not need one, since there's only one relation between these tables?
Was this page helpful?