我目前正在尝试删除一个joint
检索关联数据时添加的表数据。
查询是通过使用通过指定模型关系添加到模型的方法的sequelize来完成的(sequelize magic methods
),由于某种原因,我无法做到这一点。
我目前已尝试传递attributes: {exclude: ['...']}
到该方法,但该场仍然存在。
现任协会
// Class sequelize model
Class.belongsToMany(models.Subject, {
through: 'ClassSubject',
foreignKey: 'class_id',
otherKey: 'subject_id',
as: 'subjects'
})
// Subject sequelize model
Subject.belongsToMany(models.Class, {
through: 'ClassSubject',
foreignKey: 'subject_id',
otherKey: 'class_id',
as: 'classes'
});
查询与响应
const subjects = await dbClass.getSubjects(); // dbClass is a Class model instance
// Response
[
{
"id": "1b89d44c-2caa-452d-a1f8-7faa11970917",
"name": "Mathematics",
"code": "MATHS",
"summary": "Mathematics for class 1",
"ClassSubject": {
"class_id": "637afc7b-40f6-478e-b35e-859ca462e2e7",
"subject_id": "1b89d44c-2caa-452d-a1f8-7faa11970917"
}
}
]
所需输出
// Response
[
{
"id": "1b89d44c-2caa-452d-a1f8-7faa11970917",
"name": "Mathematics",
"code": "MATHS",
"summary": "Mathematics for class 1"
}
]
我已尝试将选项传递给下面指定的方法,但无济于事
const subjects = await dbClass.getSubjects({
attributes: { exclude: ['ClassSubject'] }
});
但还是不行。