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

186
Vistas
How to fetch data in the same order as the order of the items in the array using Sequelize

For example if the array surveyIdsArr is passed in with the following items in it.

surveyIdsArr = [
  'ac9d491d-9998-4866-956d-9d3107aa341d',
  'f71cfa71-ad1a-40dc-ad19-7f799fef0a31',
  'a9606715-c865-4f99-9afc-48b79af77caa',
  'f22c221d-2052-45af-a1ba-9774ac524a1c',
  '33c47cdb-8a66-45a8-a8ff-cc60de6ce9fc'
]

Then how to fetch the data in the same order as the elements in the array

Right now i am getting elements 33c47cdb-8a66-45a8-a8ff-cc60de6ce9fc , 22c221d-2052-45af-a1ba-9774ac524a1c, f71cfa71-ad1a-40dc-ad19-7f799fef0a31 and like this

I am using sequelize as the ORM

Following is the code to fetch the data

let fetchedSurveys = await Survey.findAndCountAll({
      where: {
        id: {
          [Op.in]: surveyIdsArr,
        },
      },
      include: [
        {
          model: User,
          as: "owner",
        },
        {
          model: Tag,
          as: "tags",
          attributes: ["id", "tagName"],
          
        },
      ],
      // helpful in lazy fetching
      offset: offset,
      limit: limit,
      distinct: true,
      col: "id",
    });
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