Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sequelize select * where attribute is NOT x

looking at the docs you can use model.findAll({where: {attribute: x}}). However, I want to select all attributes that are simply NOT x. I was looking into a regular expression here but that seemed like not an optimal solution.

What is the best way to do this?

like image 272
joemillervi Avatar asked Sep 10 '17 04:09

joemillervi


People also ask

How do you know if not equal in Sequelize?

In sql we use not equal to sign ( != ) but in sequelize we use Op.ne in query like below example.

What is findByPk?

findByPk() Finds a single active record with the specified primary key.


1 Answers

Updated method, for modern Sequelize:

model.findAll({   where: {     someAttribute: {       [sequelize.Op.not]: 'some value'     }   } }); 
like image 75
Brad Avatar answered Sep 28 '22 01:09

Brad