I’m having problems trying to apply multiple 1 to n relations to a model – the funny thing is it partly works so to clarify:
I have a “Vacancy” object, which could be created by either an “Internal” or an “Agent” those roles are separate and have their own models so I was planning to do something like this:
model Vacancy {
assignedInternalId String?
createdByInternalId String?
assignedAgentId String?
createdByInternalId String?
// Foreign Keys
assignedInternal Internal? @relation("assignedVacanciesInternal", fields: [internalId], references: [id], onDelete: SetNull)
createdByInternal Internal? @relation("createdVacanciesInternal", fields: [createdByInternalId], references: [id], onDelete: SetNull)
agent Agent? @relation("assignedVacanciesAgent", fields: [agentId], references: [id], onDelete: SetNull)
createdByAgent Agent? @relation("createdVacanciesAgent", fields: [createdByAgentId], references: [id], onDelete: SetNull)
}
model Agent {
** some more fields **
assignedVacancies Vacancy[] @relation("assignedVacanciesAgent")
createdVacancies Vacancy[] @relation("createdVacanciesAgent")
}
model Internal {
** some more fields **
assignedVacancies Vacancy[] @relation("assignedVacanciesInternal")
createdVacancies Vacancy[] @relation("createdVacanciesInternal")
}
the funny thing though is: it works for Internals this way but whenever i try to save the agent model like this it changes to this:
model Agent{
vacancies Vacancy[]
Vacancy Vacancy[]
Vacancy Vacancy[]
}
model Vacancy{
internal Internal? @relation("assignedVacanciesInternal", fields: [internalId], references: [id], onDelete: SetNull)
createdByInternal Internal? @relation("createdVacanciesInternal", fields: [createdByInternalId], references: [id], onDelete: SetNull)
agent Agent? @relation("assignedVacanciesAgent", fields: [agentId], references: [id], onDelete: SetNull)
createdByAgent Agent? @relation("createdVacanciesAgent", fields: [createdByAgentId], references: [id], onDelete: SetNull)
Agent Agent? @relation(fields: [agentId], references: [id])
}
the connections relating the agent change and autoformat while the internal ones stay the same
I have tried saving it as described above but it keeps changing the models.
Viet Nguyen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.