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

692
Visualizações
How to save multiple tables related to each other with Prisma

I'm working on a NestJS project and I have two tables (TABLE_1 and TABLE_2), TABLE_1 schema looks like this:

model TABLE 1 {
  id                            String @id @default(uuid())
  secondaryfield                String @unique @map("secondary_field") @db.VarChar(12)
  table_2                       Table_2[]
}

And table 2:

model TABLE 2 {
  id                           String @id @default(uuid())
  table_1_id                   String @unique @map("secondary_field") @db.VarChar(12)
  table_1                      Table_1 @relation(fields: [table_1_id], references: [id])
}

Since there's a FK on my table_2 that depends on table_1, and both of them will be saved at the same time, is there any way that allows Prisma to deal with this and save multiple fields (not only two like the example) with multiple relations between them? I'm using createMany() method as I usually save dozens of those at the same time.

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

0

You can try out the following:

prisma.table2.create({
  data: {
    table1: {
      createMany: {
        data: [
          {
            secondaryfield: 'table1-1',
          },
          {
            secondaryfield: 'table1-2',
          },
        ],
      }
    }
  }
})

More info here

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