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