javascript - Sequelizejs 通过两个字段“包含”
问题描述
我正在尝试将 2 个表与 sequelizejs 相关联。
表 1 具有用于关系的 ID 字段,表 2 具有用于关系的 2 个字段,一个是模块(字符串)和关系的 ID。
表 1:id order_id ...其他字段
表2:id模块relation_id'''其他字段
SQL 语法如下:
SELECT * FROM table1 AS t1
LEFT JOIN table2 AS t2 ON t1.order_id = t2.relation_id AND 'SAC' = t2.module
INNER JOIN table3 AS t3 ON t1.c_id = t3.id
WHERE t1.active = 1
sequelize 语法如下:
table1.findAll({
include: [
{
model: sequelize.models.table3
},
{
model: sequelize.models.table2,
as: 't2',
on: {
'SAC' : {$col: 't2.module'},
table1.order_id: {$col: 't2.relation_id'}
}
}
]
})
.then((result) => {
...
})
.catch((err) => {
...
});
但是 sequelize 给了我下一个错误:
Error => { SequelizeEagerLoadingError: t2 is not associated to table1!
我感谢你的帮助
解决方案
推荐阅读
- javascript - 使用标准的js类在vue js中创建实例
- neo4j - Neo4J 检查用户是否关注我
- python - 通过信号/槽连接传递的属性失去其类型
- java - 从执行器信息中隐藏构建信息 Spring boot
- indexing - 产品平面数据索引异常:SQLSTATE[42S22] [安装 Magento 2.4.1 和 2.4.3 企业版时] 重新索引问题
- computer-vision - 无法使用 vimbasrc 保存视频
- python - 如何在python数据框中的单行中连接同一主题ID的列句子?
- python - 在 PC 启动时使用命令运行 PyCharm
- c# - 如何在某个日期之后读取日志文件?
- php - Firebase 远程身份验证