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

180
Visualizações
Sequelize returns empty model from certain nested level

I've got a model I'm trying to query and I'm trying to include some very nested models (which their relation varies between hasOne to hasMany) to it, yet it seems that from a certain level the object comes back and an empty model

const parent = Parent.findByPk(id, {include: ["anotherChild", 
    {model: Child1, as: "child1", include: [
            {model: Child2, as: "children2", include: [
                {model: Child3, as: "child3", include: [
                    {model: Child4, as: "children4", include: [
                        {model: Child5, as: "children5"}
                    ]}
                ]}
            ]}
        ]}
    ]});

When I try to print the most nested child, I receive a model instance but with no values (there are matching results, otherwise it would also just set them as null)

console.log(parent.child1.children2[0].child3.children4[0].children5[0]);
// prints:
// Child5 {
//   dataValues: { '': null },
//   _previousDataValues: { '': null },
//   ....
// }

when I try to separate the query it does work

const parent = Parent.findByPk(id, {include: ["anotherChild", {model: Child1, as: "child1"}]});

const fromChild1 = Child1.findByPk(parent.child1.id, include: [
            {model: Child2, as: "children2", include: [
                {model: Child3, as: "child3", include: [
                    {model: Child4, as: "children4", include: [
                        {model: Child5, as: "children5"}
                    ]}
                ]}
            ]}
        ]
   );

result in the following value:

console.log(fromChild1.children2[0].child3.children4[0].children5[0]);
// prints:
// Child5 {
//   dataValues: { 'realKey': 'realValue', 'realData': 'someData'... },
//   _previousDataValues: { 'realKey': 'realValue, 'realData': 'someData'... },
//   ....
// }

Why is that, and how could I get over that? (using {all: true, nested: true} is not possible due to belongsTo / belongsToMany relationships between them)

about 4 years ago · Juan Pablo Isaza
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