如何将 include 与属性一起使用并进行后续处理?

知道如何将 include 与属性(当您只需要包含所包含表中的特定字段时)一起用于 Sequelize 吗?

目前我有这个(但它不像预期的那样工作) :

var attributes = ['id', 'name', 'bar.version', ['bar.last_modified', 'changed']];
foo.findAll({
where      : where,
attributes : attributes,
include    : [bar]
}).success(function (result) { ...
128269 次浏览

Something like this should work

foo.findAll({
where      : where,
attributes : attributes,
include    : [{ model: bar, attributes: attributes}]
}).success(function (result) {

We can do something like that for exclude or include specific attribute with sequelize in Node.js.

Payment.findAll({
where: {
DairyId: req.query.dairyid
},
attributes: {
exclude: ['createdAt', 'updatedAt']
},
include: {
model: Customer,
attributes:['customerName', 'phoneNumber']
}
})

Use the select without hyphen (-) only blank spaces like this.

Model.find().select('attr1 attr2 attr3')
Course.findAll({where: {
status:responseCode.STATUS_ACTIVE
}, attributes:['id','course_title','course_slug','age_group','image','class_duration','no_of_classes','is_course_upcoming'],
order:[['is_sorting','ASC']],
include:{model:Section,attributes:['id','title','course_id','start_date','end_date']},
}).then(course_detail =>{
result(null,course_detail);
}).catch(err =>{
console.log(err)
});