Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

154
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!