Nested relations with Sequelize
Sequelize Docs: Nested Eager Loading
Example
Issue.find({ include: [ { model: Invite, include: [Group] } ]});
If you want to eager load all nested associations use this function.
Issue.find({ include:getNestedAssociations(Issue)});//Recursively load all bested associtiaonsfunction getNestedAssociations(_model) { const associations = []; for (const association of Object.keys(_model.associations)) { const model = _model.associations[association].target; const as = association; const include = getNestedAssociations(model); associations.push({ model: model, as: as, ...(include && { include: include }), }); } return associations;}
After loosing all the hopes, I lastly just tried one random hit snd that worked.Just send attributes with empty array, then it wont be included in results
{ model: User, as: 'users', attributes: [], // This will work// where: { user_id: 1 } }