P
Prisma4mo ago
ʞk

Does it make sense to create an explicit one-to-many relation?

I'm reading the docs but can't find an example of an explicit one-to-many relation. Maybe it doesn't make sense to create an explicit one-to-many relation?
2 Replies
ʞk
ʞkOP4mo ago
Current approach that doesn't work:
datasource db {
provider = "mongodb"
url = env("DATABASE_URL")
}

model Stage {
id String @id @default(auto()) @map("_id") @db.ObjectId
cuid String @unique @default(cuid())
name String @unique

events StageEventsMap[]
}

model Event {
id String @id @default(auto()) @map("_id") @db.ObjectId
cuid String @unique @default(cuid())
name String

stage StageEventsMap
}

model StageEventsMap {
id String @id @default(auto()) @map("_id") @db.ObjectId
cuid String @unique @default(cuid())

stage Stage @relation(fields: [stageId], references: [id])
events Event[] @relation(fields: [eventIds], references: [id])

stageId String @db.ObjectId
eventIds String[] @db.ObjectId

@@index([stageId, eventIds])
}
datasource db {
provider = "mongodb"
url = env("DATABASE_URL")
}

model Stage {
id String @id @default(auto()) @map("_id") @db.ObjectId
cuid String @unique @default(cuid())
name String @unique

events StageEventsMap[]
}

model Event {
id String @id @default(auto()) @map("_id") @db.ObjectId
cuid String @unique @default(cuid())
name String

stage StageEventsMap
}

model StageEventsMap {
id String @id @default(auto()) @map("_id") @db.ObjectId
cuid String @unique @default(cuid())

stage Stage @relation(fields: [stageId], references: [id])
events Event[] @relation(fields: [eventIds], references: [id])

stageId String @db.ObjectId
eventIds String[] @db.ObjectId

@@index([stageId, eventIds])
}
ʞk
ʞkOP4mo ago
No description
No description
No description
Want results from more Discord servers?
Add your server