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

436
Vistas
How to retrieve a list of values from a list of objects?

So I have a list of objects like this formed by Sequelize query:

  [
  Likes {
    dataValues: { PlaceId: 'e61d2360-c846-46b5-aa25-6534d38276dd' },
    _previousDataValues: { PlaceId: 'e61d2360-c846-46b5-aa25-6534d38276dd' },
    _changed: Set(0) {},
    _options: {
      isNewRecord: false,
      _schema: null,
      _schemaDelimiter: '',
      raw: true,
      attributes: [Array]
    },
    isNewRecord: false
  },
  Likes {
    dataValues: { PlaceId: '417f55a6-1d64-491f-9c00-8f3094f3f53a' },
    _previousDataValues: { PlaceId: '417f55a6-1d64-491f-9c00-8f3094f3f53a' },
    _changed: Set(0) {},
    _options: {
      isNewRecord: false,
      _schema: null,
      _schemaDelimiter: '',
      raw: true,
      attributes: [Array]
    },
    isNewRecord: false
  }
]

I am getting various exceptions when querying because I get either a list like that: [{PlaceId: 'e61d2360-c846-46b5-aa25-6534d38276dd'}, {PlaceId: 'e678yt6-c846-46b5-aa25-6534d67326au'}] or an empty list: [].

I tried out Object.values as well as valueOf, map and other built in methods - even a manual for cycle and I do not really get why don't they work. What methods of achieving that can you suggest?

Solution:

return  models.Likes.findAll({
            where: {
                UserId: req.user.id
            },
            attributes: ['PlaceId']
        }).then(likes => {
            var values;
            try {
                values = likes.map(entity => entity.get('PlaceId'))
            }
            catch (e){
                console.log(e);
            }
            models.Place.findAll({
                where: {
                    id: {
                        [Sequelize.Op.notIn]: values
                    }
                },
                limit: 24
            })

This is the final working solution written thanks to one of the suggestions. Mapping with (entity => entity.get) did the trick. Best regards to everybody who commented and helped.

If anybody needs, the thing does a sequelize query from one table to then query another table with a "NOT IN". In SQL query 2ould look like that:

"SELECT "id", "coordinates", "place_name", "description", "category", "createdAt", "updatedAt" FROM "Places" AS "Place" WHERE "Place"."id" NOT IN ('e61d2360-c846-46b5-aa25-6534d38276dd', '417f55a6-1d64-491f-9c00-8f3094f3f53a') LIMIT 24;"
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

I would say, it should be sufficiant for you

const FirstTable = sequelize.model(`FirstTable`)
const list = await FirstTable.findAll({
    attributes: [`PlaceId`]
})
    .then(data => {
        return data.map(entity => entity.get('PlaceId'))
    })
console.log(list)

The output will be:

[
  'e61d2360-c846-46b5-aa25-6534d38276dd',
  'e678yt6-c846-46b5-aa25-6534d67326au'
]
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