Skip to content
Discussion options

You must be logged in to vote

When you need to store additional information about the relationship itself (such as enrolledAt, progress, or status), an explicit many-to-many relation is the recommended approach.

Instead of using Prisma's implicit many-to-many relation, create a dedicated join model.

Example:

model User {
id String @id @default(cuid())
enrollments Enrollment[]
}

model Course {
id String @id @default(cuid())
enrollments Enrollment[]
}

model Enrollment {
userId String
courseId String

enrolledAt DateTime @default(now())
progress Int @default(0)
status String

user User @relation(fields: [userId], references: [id])
course Course @relation(fields: [courseId], references: [id])

@@id([userId, courseId])
}

Usin…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by mhasan2306
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question Ask and answer questions about GitHub features and usage Programming Help Discussions around programming languages, open source and software development Welcome 🎉 Used to greet and highlight first-time discussion participants. Welcome to the community! source:ui Discussions created via Community GitHub templates
2 participants