ShaDoW
ShaDoW
PPrisma
Created by ShaDoW on 5/15/2024 in #help-and-questions
Need help with schema
I have models - Question and Answer There is a one to many relation : 1 Question has many Answers But I also need a relation for a single Answer, I will show the schema file, it is currently giving me error
model Question {
id Int @id @default(autoincrement())
title String
points Int?
quiz Quiz @relation(fields: [quizId], references: [id])
quizId Int
answers Answer[]
correctAnswerId Int?
correctAnswer Answer? @relation(name: "correctAnswer", fields: [correctAnswerId], references: [id])
}

model Answer {
id Int @id @default(autoincrement())
title String
question Question @relation(fields: [questionId], references: [id])
questionId Int
}
model Question {
id Int @id @default(autoincrement())
title String
points Int?
quiz Quiz @relation(fields: [quizId], references: [id])
quizId Int
answers Answer[]
correctAnswerId Int?
correctAnswer Answer? @relation(name: "correctAnswer", fields: [correctAnswerId], references: [id])
}

model Answer {
id Int @id @default(autoincrement())
title String
question Question @relation(fields: [questionId], references: [id])
questionId Int
}
3 replies