Where condition for joined table in Sequelize ORM

前端 未结 2 764
失恋的感觉
失恋的感觉 2020-12-13 02:15

I want to get query like this with sequelize ORM:

SELECT \"A\".*,      
FROM \"A\" 
LEFT OUTER JOIN \"B\" ON \"A\".\"bId\" = \"B\".\"id\"
LEFT OUTER JOIN \"         


        
相关标签:
2条回答
  • 2020-12-13 02:28

    Add the where condition in the include, along with join.

        {
           model: C,
           where: {
            id: 1
           }
       }
    
    0 讨论(0)
  • 2020-12-13 02:35

    Wrap the columns which reference joined tables in $$

    A.findAll({
        where: {
            $or: [
                {'$B.userId$' : 100},
                {'$C.userId$' : 100}
            ]
        },
        include: [{
            model: B,
            required: false
    
        }, {
            model: C,
            required: false
        }]
    }); 
    
    0 讨论(0)
提交回复
热议问题