是否有任何可能的方法来重现此查询
select table2.node_id as id, table2.client_id as clientId, table1.collection_id as collectionId from table1 inner join table2 on table2.primary_collection_id = table1.collection_id
在sequelize orm?
我定义了hasOne
和belongsTo
关系并尝试这样做:
return Models.FileModel.findAll({
include: [
{ model: Models.NodeModel, required: true}
]
});
但我的inner join
条件不正确:
inner join table2 on table2.node_id = table1.collection_d
需要将table2.node_id
替换为table2.primary_collection_id
答案 0 :(得分:0)
嗯,有时在阅读文档时需要更加专注。
我在寻找targetKey
所以我定义了关联
FileModel.belongsTo(NodeModel, {foreignKey: 'collection_id', targetKey: 'primary_collection_id'});
它对我有用