我的MySQL数据库表关系如下
db.teble1.belongsToMany(db.teble2, { through: 'teble1_teble2', foreignKey: 'teble1Id', otherKey: 'teble2Id' });
db.teble2.belongsToMany(db.teble1, { through: 'teble1_teble2', foreignKey: 'teble2Id', otherKey: 'teble1Id' });
db.teble3.hasMany(db.teble4, {foreignKey: 'teble3Details', sourceKey: 'teble3Id'});
db.teble4.belongsTo(db.teble3, {foreignKey: 'teble3Details', targetKey: 'teble3Id'});
db.teble1.hasMany(db.teble3, {foreignKey: 'teble1Details', sourceKey: 'teble1Id'});
db.teble3.belongsTo(db.teble1, {foreignKey: 'teble1Details', targetKey: 'teble1Id'});
db.teble2.hasMany(db.teble4, {foreignKey: 'teble2Details', sourceKey: 'teble2Id'});
db.teble4.belongsTo(db.teble2, {foreignKey: 'teble2Details', targetKey: 'teble2Id'});
我想要如下查询。我不知道如何用table4检查table2Id
db.teble2.findAll({
as:'table2Val'
include: [{
model: db.table1,
include: [{
model: db.table3,
include: [{
model: db.table4,
where:{
table2Details: table2Val.teble2Id
}
}]
}]
}]
}).then(table2 => {
res.send(table2);
});
任何人都可以帮助我。预先感谢。