I'm newbie for Sequelize
I have a problem with "Nested Eager Loading"
I have 2 Table with 1-to-many relationship
Comment Table
User Table
I use this code for the query
Comment.findAll({
include: [User]
})
I got
{
id: 1,
comment: "test",
user: {
id: 3,
name: "someone"
}
}
But I expected result like this
{
id: 1,
comment: "test",
user_id: 3,
user_name: "someone"
}
I read several stackoverflow post it has a solution but work for version 3.3
Comment.findAll({
attributes: ['id', 'name', ['user.id','user_id'], ['user.name','user_name']]
include: [{ model: User, attributes:[], nested: false, required: true }]
})
Comment.findAll({
attributes: ['id', 'name', [Sequelize.col('user.id'),'user_id'], [Sequelize.col('user.name'),'user_name']]
include: [{ model: User, attributes:[], nested: false, required: true }]
})
but it's not work for me.
now I use sequelize 5.5.1 how can I implement it.
Can someone help me, please?