2017-02-03 1 views
0

はsequelizeのORMでこのクエリsequelizeで列名の表を結合するにはどうすればいいですか?

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 

を再現するすべての可能な方法はありますか?

私はhasOnebelongsTo関係を定義し、そうしようとした:

return Models.FileModel.findAll({ 
    include: [ 
     { model: Models.NodeModel, required: true} 
    ] 
}); 

しかし、私はinner join条件間違っている: inner join table2 on table2.node_id = table1.collection_d

が時々必要、まあtable2.primary_collection_id

+0

Plsのは、あなたがテーブル間のリレーションシップを設定するコードを含んで私の作品targetKey

を探していました。 – Shadow

答えて

0

table2.node_idを交換する必要がありますドキュメントを読むときにもっと注意してください。 私は、だから私は協会

FileModel.belongsTo(NodeModel, {foreignKey: 'collection_id', targetKey: 'primary_collection_id'}); 

を定義し、それが

関連する問題