【发布时间】:2020-04-13 20:59:29
【问题描述】:
我有 3 个模型:报表、分支、客户端。
Report.belongsTo(Branch);
Branch.belongsTo(Client);
在使用相关分支和客户端查询报表时,我运行 2 个查询:
Report.findOne({
where:{id:reportId},
include: [{
model: Branch,
attributes: ['name','clientId']
}]
})
.then((report)=>{
const clientId = report.dataValues.branch.clientId;
Client.findOne({
where:{id:clientId},
})
.then((client)=>{
console.log('client is ', client);
});
})
.catch();
我可以只用一个连接 Report->Branch->Client 的查询来查询数据吗?
【问题讨论】:
标签: sequelize.js