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

236
Vistas
Sequelize, lazy loading on associated models

I am using sequelize 6.17

I have a class Folders which has many childFolders and files.

I would like to lazy load the childFolders and files that are on the association.

const folderContent = await db.folders.findAll({
            where: {
               parentFolderId: 123
            },
            limit,
            offset,
            include: [
               {
                  model: db.folders,
                  as: "childFolders",
                  required: false
               },
               {
                  model: db.files,
                  as: "files",
                  required: false
               }
            ],
         });

This will not work and will return folderContent.files and folderContent.childFolders.

Would be possible to get x amount of childFolders and when there is not anymore childFolders to start getting the files? Can this be returned as an array of childFolders and files?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

By indicating include option you perform eager loading and you will get all-in-one. If you wish to get childFolders or files separately for a certain folder model instance you need to call special methods getChildFolders or getFiles (generated by Sequelize):

const folderContent = await db.folders.findAll({
            where: {
               parentFolderId: 123
            },
            limit,
            offset,
         });

for (const folder of folders) {
  const files = await folder.getFiles();
  const childFolders = await folder.getChildFolders();
}
over 4 years ago · Santiago Trujillo Denunciar
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