1. left join (相对于base_admin)
- sql:
select *
from author
left join book
on book.authorId = author.id
- sequelize-typescript:
let options = {
raw:true,
include:[{
model:book
}]
}
author.findAndCountAll(options).then(results => {
console.log("results.rows:",results.rows)
})
2. ringt join(相对于base_admin)
备注:就是left join 的反过来查询
- sql:
select *
from book
left join author
on author.bookId = book.id
- sequelize-typescript:
let options = {
raw:true,
include:[{
model:author,
where:{
id:{
[Sequelize.Op.ne]:null //过滤掉无效的数据
}
}
}]
}
book.findAndCountAll(options).then(results => {
console.log("results.rows:",results.rows)
})
网友评论