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

228
Visualizações
Creating indirect references with Prisma

The Prisma documentation contains an example on how to create nested records (shortened):

const user = await prisma.user.create({
  data: {
    email: 'yvette@prisma.io',
    name: 'Yvette',
    posts: {
      create: [
        {
          title: 'How to make an omelette',
          categories: {
            create: {
              name: 'Easy cooking',
            },
          },
        },
      ],
    },
  },
})

Lets say I also need to reference the created user from the created category ("creator" or so). Prisma won't fill in the user-id as it does with direct references, but I also do not have the user-id to specifiy it myself in the data. If I understand Prisma-transactions correctly, I can also not create the records first without the reference from the category to the user, and add the missing reference afterwards but within the same transaction.

So how do you do something like this (my use case is slighty different but comparable) in a safe way?

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

0

I think an Interactive Transaction would work here.

Simply create a transaction where:

  1. Create the "creator" or "user" record first.
  2. Use the returned object from the "creator" record and reference its id as you please when creating the "posts"/dependent record.

1 and 2 are separate Prisma queries here (not a single nested write).

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