我正在使用Sequelize ORM和Node.js,我无法理解如何用它构建以下查询.
SELECT service.*, serviceCollection.*, client.companyName, client.idclient
FROM service
INNER JOIN serviceCollection
ON service.serviceCollection_idserviceCollection = serviceCollection.idserviceCollection
INNER JOIN client
ON serviceCollection.client_idclient = client.idclient
Run Code Online (Sandbox Code Playgroud)
当我在phpMyAdmin上尝试时,此查询可以正常运行.复杂的是客户端模型与Service没有直接关系,因此在尝试执行此操作时:
Service.findAll({include : [ServiceCollection, Client]}).then(function(service){
if(service) {
res.status(200).json(service);
}
});
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Unhandled rejection Error: client is not associated to service!
Run Code Online (Sandbox Code Playgroud)
我如何准备查询的方式是从serviceCollection中的foreignkey获取客户端信息,而不是原始模型 - service.我不能只include在客户端使用,因为它会给我错误,我需要将其与其他方式的查询相关联,我似乎无法在文档中找到解决方案.