#Quick question on relations
3 messages · Page 1 of 1 (latest)
Here's ChatGPT's response, is this the norm or is this outdated?
model User {
id Int @id @default(autoincrement())
username String
email String @unique
role String // You can use an Enum type here if roles are predefined
// Add other fields specific to each role
employeeProfile EmployeeProfile? @relation(fields: [id], references: [userId])
teacherProfile TeacherProfile? @relation(fields: [id], references: [userId])
principalProfile PrincipalProfile? @relation(fields: [id], references: [userId])
}
model EmployeeProfile {
id Int @id @default(autoincrement())
userId Int
// Add fields specific to employees
// ...
user User @relation(fields: [userId], references: [id])
}
model TeacherProfile {
id Int @id @default(autoincrement())
userId Int
// Add fields specific to teachers
// ...
user User @relation(fields: [userId], references: [id])
}
model PrincipalProfile {
id Int @id @default(autoincrement())
userId Int
// Add fields specific to principals
// ...
user User @relation(fields: [userId], references: [id])
}
I think I'm gonna go with the Table-Per-Type solution