0
如何從同一個表中選擇兩次Sequelize? 這裏是MySQL代碼:Sequelize MySQL從同一個表中選擇(左連接)
select b.*, a.parent_id
from theSameTable as b left join theSameTable as a on b.parent_id = a.id
這裏是我的MySQL表
這裏是我的Sequelize代碼
const db = await ec.sequelize.define(tableDb, {
id: {
type: ec.Sequelize.INTEGER.UNSIGNED,
primaryKey: true,
autoIncrement: true
},
url: ec.Sequelize.STRING(511),
url_hash: ec.Sequelize.STRING(32),
name: ec.Sequelize.STRING(511),
full_name: ec.Sequelize.STRING(511),
parent_id: ec.Sequelize.INTEGER(11).UNSIGNED,
cnt: ec.Sequelize.STRING(255),
chk: ec.Sequelize.INTEGER(1)
}, {
indexes: [{
unique: true,
fields: ['url_hash']
}]
});
await ec.sequelize.sync();
你是怎麼找到谷歌上搜索有關自聯接的sequelize? – philipxy
[使用Sequelize查詢自連接,包括相關記錄]的可能重複(https://stackoverflow.com/questions/40294776/query-self-join-with-sequelize-including-related-record) – philipxy