Hi! I've been trying to map multiple fields to the...
# orm-help
m
Hi! I've been trying to map multiple fields to the same model and I've read about needing to add name etc to disambiguate but I'm wanting to map to the same field in the shared model, is there a way to accomplish that?
What I'd like to do is approximately:
Copy code
model Result {
  id                      String             @id @default(cuid())
  firstSurveyScore Int
  firstSurvey   ExampleSurvey @relation(fields: [firstSurveyId], references: [id])
  firstSurveyId String             
  secondSurveyScore Int
  secondSurvey    ExampleSurvey @relation(fields: [secondSurveyId], references: [id])
  secondSurveyId  String          
}

model ExampleSurvey {
  id                      String             @id @default(cuid())
  result   Result
  resultId String
}
But I seem to have to do something akin to
Copy code
model Result {
  id                String         @id @default(cuid())
  firstSurveyScore  Int
  firstSurvey       ExampleSurvey? @relation(name: "first-survey", fields: [firstSurveyId], references: [id])
  firstSurveyId     String?        @unique
  secondSurveyScore Int
  secondSurvey      ExampleSurvey? @relation(name: "second-survey", fields: [secondSurveyId], references: [id])
  secondSurveyId    String?        @unique
}

model ExampleSurvey {
  id           String  @id @default(cuid())
  firstResult  Result? @relation(name: "first-survey")
  secondResult Result? @relation(name: "second-survey")
}
Which leaves me with two optional Ids in ExampleSurvey despite survey always mapping into the singular result
Granted my actual naming/structure is different in the real project but this is the most simple version of the concept