node.js sequelize: multiple 'where' query conditions


How do i query a table with multiple conditions? Here are the examples both working:

Post.findAll({ where: ['deletedAt IS NULL'] }).success()


Post.findAll({ where: {topicId:} }).success()

Then, if i need conditions combined, i feel like i need to do something like

Post.findAll({ where: [{topicId:}, 'deletedAt IS NULL'] }).success()

, but it doesn't work.
What is the syntax the sequelize waits for?

node debug says:

DEBUG: TypeError: Object # has no method 'replace'

if it matters...

5/29/2012 10:42:56 PM

Accepted Answer

Please note that as of this posting and the most recent version of sequelize, the above answers are out of date. I am posting the solution that I got working in hopes of saving someone some time.

filters["State"] = {$and: [filters["State"], {$not: this.filterSBM()}] };

Note the $ and array inside the JSON object and lack of ? token replacement.

Or put in a more general way, since that might help someone wrap their head around it:

{ $and: [{"Key1": "Value1"}, {"Key2": "Value2"}] }
4/29/2015 6:52:19 PM

You can do:

Post.findAll({ where: {deletedAt: null, topicId:} })

Which would be translated to deletedAt IS NULL

BTW, if you need deletedAt NOT IS NULL, use:

Post.findAll({ where: {deletedAt: {$ne: null}, topicId:} })

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow