Sequelize select only chosen attributes Sequelize select only chosen attributes express express

Sequelize select only chosen attributes


You can do something like the following

models.modelA.findAll({        attributes: [           'id'        ],        raw: true,        include:            [                {                    model: models.modelB,                    attributes: ['fieldName1', 'fieldName2'], // Add column names here inside attributes array.                    required: true                }            ]    }).then(function (tenants) {    });


You can try sending empty array as attributes to exclude them:

models.modelA.findAll({            attributes: [               ['modelA.id','id']            ],            raw: true,            include:                [                    {                        model: models.modelB,                        attributes: [],                        required: true                    }                ]        }).then(function (tenants) {        });