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?