FM-96
FM-96
PPrisma
Created by FM-96 on 5/2/2024 in #help-and-questions
Strange @relation fields in auto-generated models
Using [email protected], 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)
}
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?
2 replies