ʞk
ʞk
PPrisma
Created by ʞk on 8/5/2024 in #help-and-questions
Does it make sense to create an explicit one-to-many relation?
No description
3 replies
PPrisma
Created by ʞk on 8/5/2024 in #help-and-questions
Does it make sense to create an explicit one-to-many relation?
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])
}
3 replies