我正在使用MySQL数据库:
models.modelA.findAll({
attributes: [
['modelA.id','id']
],
raw: true,
include:
[
{
model: models.modelB,
required: true
}
]
}).then(function (tenants) {
});
尽管如此,我只选择了id
,Sequelize也从相关表格中检索所有属性,所以我得到{id
,...这里的所有属性}。
我怎么能阻止这个?有时我想只选择2/3列,而Sequelize总是选择所有不高效的列。
您可以执行以下操作
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) {
});