Mysql 如何在sequelize中连接列名上的表?
是否有任何可能的方法重现此查询Mysql 如何在sequelize中连接列名上的表?,mysql,node.js,sequelize.js,Mysql,Node.js,Sequelize.js,是否有任何可能的方法重现此查询 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 在续集中 我定义了hasOne和belongsTo关系,并尝试这样做: return Models.
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
在续集中
我定义了hasOne
和belongsTo
关系,并尝试这样做:
return Models.FileModel.findAll({
include: [
{ model: Models.NodeModel, required: true}
]
});
但是我有不正确的内部连接
条件:
表2上的内部联接表2.node\u id=table1.collection\u d
需要将表2.node\u id替换为表2.primary\u collection\u id好吧,有时在阅读文档时需要更加注意。 我在找
targetKey
所以我定义了联想
FileModel.belongsTo(NodeModel, {foreignKey: 'collection_id', targetKey: 'primary_collection_id'});
这对我很有用请包括设置表之间关系的代码。