使用多个或续集

问题描述 投票:1回答:1

我想在sequelize中使用3或条件写一点复杂的where

SQL where示例:

where 
(c1 = 'a' or c2 = 'b' or c3 = 'c' or c4 = 'd') 
and (c5 = 'e' or c6 = 'f' or c7 = 'g' or c8 = 'h') 
and (c9 = 'i' or c10 = 'j')

在sequelize中我写了这样的东西:

where: {
  $and: {
    $or: [{ c1: 'a' }, { c2: 'b' }, { c3: 'c' }, { c4: 'd' }]
  },
  $or: [{ c5: 'e' }, { c6: 'f' }, { c7: 'g' }, { c8: 'h' }]
}

但是我怎么能添加这个对象:$or: [{ c9: 'i' }, { c10: 'j' }]

附:不要担心项目我使用Op

javascript node.js database sequelize.js where
1个回答
1
投票

你需要一个外部$and属性与内部部分的条款。

where: {
    $and: [
        {
            $or: [
                { c1: 'a' }, { c2: 'b' }, { c3: 'c' }, { c4: 'd' }
            ]
        },
        {
            $or: [
                { c5: 'e' }, { c6: 'f' }, { c7: 'g' }, { c8: 'h' }
            ]
        },
        {
            $or: [
                { c9: 'i' }, { c10: 'j' }
            ]
        }
    ]
}
© www.soinside.com 2019 - 2024. All rights reserved.