Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

171
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda