Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

155
Visualizações
Flatten object in side an array of assosiated table in Sequelize

I have a Sequelize query with multiple associations.

let res = await models.Patients.findAll({
    include: [
        {
            model: models.Physicians,
            required: true,
            attributes: [ 'id' ],
            include: [ {
                model: models.PII,
                required: true,
                attributes: [ 'firstName' ]
            }
    ]
})

The results comes as following:

[{
    patientName: "test",
    physicians: [
            {
                id: '176735',
                PII: {
                         firstName: 'testP'
                     }
            }
    ]
}]

I want the objects in the physicians array to be flat as following:

[{
    patientName: "test",
    physicians: [
            {
                id: '176735',
                firstName: 'testP'
            }
    ]
}]

I tried using: [sequelize.col('PII.firstName'),'firstName'] in the physicians table attributes and I got the error: "Column physicians.PII.firstName does not exists"

Any suggestions please how solve this issue?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda