sequelize-typescript 的 left join

2019-02-27  本文已影响2人  AsaGuo

1. left join (相对于base_admin)

select * 
  from author
  left join book
    on book.authorId = author.id
    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 的反过来查询

select * 
  from book
  left join author
    on author.bookId = book.id
    let options = {
        raw:true,
        include:[{
            model:author,
            where:{
                id:{
                    [Sequelize.Op.ne]:null //过滤掉无效的数据 
                }
            }
        }]
    }
    
    book.findAndCountAll(options).then(results => {
        console.log("results.rows:",results.rows)
    })
上一篇下一篇

猜你喜欢

热点阅读