Fabio Espinosa
Fabio Espinosa

Reputation: 1012

Querying twice with same operator in Sequelize

Say I wanted to query for Posts where the content is either like 'good' and either like 'bad', then i'd do this:

Post.findAll({
  where:{
        content: {
            [Op.and]: {
                [Op.like]: '%good%',
                [Op.like]: '%bad%'
            }
        }
  }
}

But since the object has both properties named [Op.like], the latter one will replace the one above.

So I find no way to be able to query using the same operator

Upvotes: 1

Views: 336

Answers (1)

Vivek Doshi
Vivek Doshi

Reputation: 58593

I think you can do it like :

[Op.and]: [
    { [Op.like]: '%good%' } ,
    { [Op.like]: '%bad%' }
]

Upvotes: 4

Related Questions