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

469
Vistas
How to return result from include model in same level of main model in Sequelize?

This is the code and result that I have done in my project. I would like to get the result of include model in the same result with the main model. the below code is what I have done.

Sequelize query:

 User.findAll({
        include: [{
                model: Position,
                attributes: ['POSITION_NAME'],
            }
        ]
    }).then(user => {
        res.json({
            data: user
        })
    }).catch(error => {
        console.log(error)
    })

result that I get

     [
        {
            "ID": 2,
            "NAME": "AAA",
            "LAST_NAME": "BBB",
            "Position": {
                "POSITION_NAME": "ວິຊາການສັນຍາຈ້າງ"
            }
        }
]

result that I want:

     [
        {
            
        "ID": 2,
        "NAME": "AAA",
        "LAST_NAME": "BBB",
        "POSITION_NAME": "ວິຊາການສັນຍາຈ້າງ"
        }
]
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

try like this .

User.findAll({
    attributes: ["ID", "NAME", ["Position.POSITION_NAME", "POSITION_NAME"]],
    include: [{
        model: Position,
        attributes: [],
    }
    ],
    raw:true
}).then(user => {
    res.json({
        data: user
    })
}).catch(error => {
    console.log(error)
})
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