const Contentdata = await question.findAll({
attributes: [`id`, `question`],
include: [{
model: option,
attributes: ['id', 'option','option_es',
[sequelize.literal('(SELECT case when count(*)=0 then "0" else "1" end FROM `answer` WHERE `userid`=' + userid + ' and `optionid`=options.id)'), 'answer'],
],
on: {
col1: sequelize.where(sequelize.col('options.questionid'), '=',
sequelize.col('question.id')),
},
include: [{
model: focuson,
attributes: ['id', 'focuson', 'optionid',
[sequelize.literal('(SELECT case when count(*)=0 then "0" else "1" end FROM
`focuson_answer` WHERE `userid`=' + userid + ' and `focusonid`=focusons.id)'), 'answer'],
],
}]
}]
});
In the above example I not able to use focus on object as it gives the error "column focusons.id" does not exist, whereas if I pull it out of the nested include it does not show this error. Also if I try to apply to join here it also needs to access the column but it's not.