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

431
Visualizações
findAll() in Sequelize doesn't find a row created inside a transaction

I'm having a problem when creating a row and later on selecting it while still under the same transaction.

Whenever I execute the following code I usually get an empty array and rarely get an array with the newly created row.

This is a sample of the code I run:

return seq.transaction((tx) => {
    const options = {transaction: tx};
    return model.create(user, options)
    .then(() => {
        return model.findAll({
            include: {
                all: true
            }
    }, options)
    .then((data) => ({
        console.log(data);
    });
});

Is there something basic I'm missing here? Thanks!

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

I solved the problem. What I did wrong was giving the transaction to the findAll() function as an additional argument instead of part of the first argument's JSON.

So instead of:

return model.findAll({
    include: {
        all: true
    }
}, options)

I should've done:

return model.findAll({
    include: {
        all: true
    },
    transaction: options.transaction
});

Hope this solution will be helpful for other people.

over 4 years ago · Santiago Trujillo 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