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

135
Visualizações
Multiple includes in one model querying

sorry about my English. I want to do multiple include associations within a findOne using sequelize. When I do separate includes everything works perfectly. I'll contrast below what works and what doesn't.

// that doesn't work
const post = await Post.findOne({
         where: { post_url: post_url },
         include: { // this include dont work
            association: 'postAuthor',
            attributes: ['name'],
         },
         include: {
            association: 'comments',
            attributes: ['comment'],
            include: {
               association: 'commentAuthor',
               attributes: ['name']
            }
         }
      });

But if I make each sentence separate it works

// this work
     include: {
            association: 'postAuthor',
            attributes: ['name'],
         },

Again sorry for the English.

In short, I need to make both includes work at the same time. The include inside the include works perfectly (commentAuthor In comments).

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

0

      where: { post_url: post_url },
         include: [
            { association: 'postAuthor', attributes: ['name'] },
            {
               association: 'comments', attributes: ['comment'],
               include: [{
                  association: 'commentAuthor',
                  attributes: ['name']
               }]
            }
         ]
      });
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