Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

128
Visualizações
Can I map two columns in a one-to-many relationship in Prisma?

I'm trying to create a prisma schema, where I have an Order model, and a Client model. I would like to have a one-to-many relation between clients and orders.

I have it working with this Order model:

clientId     Client            @relation(fields: [clientId], references: [id])
clientId     Int

But wanted to also include the client name. Something like this doesn't work:

client       Client            @relation(fields: [clientName, clientId], references: [name, id])
clientName   String
clientId     Int

This gives me the error

Error validating: The argument `references` must refer to a unique criteria in the related model `Client`. But it is referencing the following fields that are not a unique criteria: name, id

Is this something that is possible within the Prisma schema? I can do it with my controller in NestJS, but ideally I would want to be done in the Prisma layer.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I solved this by adding a @@unique([name, id]) constraint on the Client model. However, I'm not sure if this is the correct or best way to do this.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda