sorry about my English. I want to do multiple include associations within a findOne using sequelize. When I do separate includes everything works perfectly. I'll contrast below what works and what doesn't.
// that doesn't work
const post = await Post.findOne({
where: { post_url: post_url },
include: { // this include dont work
association: 'postAuthor',
attributes: ['name'],
},
include: {
association: 'comments',
attributes: ['comment'],
include: {
association: 'commentAuthor',
attributes: ['name']
}
}
});
But if I make each sentence separate it works
// this work
include: {
association: 'postAuthor',
attributes: ['name'],
},
Again sorry for the English.
In short, I need to make both includes work at the same time. The include inside the include works perfectly (commentAuthor In comments).
where: { post_url: post_url },
include: [
{ association: 'postAuthor', attributes: ['name'] },
{
association: 'comments', attributes: ['comment'],
include: [{
association: 'commentAuthor',
attributes: ['name']
}]
}
]
});