Muhammad Fazeel
Muhammad Fazeel

Reputation: 568

Sequelize Query Where not equal and Other Conditions

I want to make the query id not equal in Sequelize.

Here is my current sequelize query:

return db.Area.findAll({
    where: { id: { $ne: Id },
    slug: conditions.slug }
})

The resulting SQL Query:

*SELECT `id`, `title`, `name`, `titleL1`, `nameL1`, `level`, `slug`, `createdAt`, `updatedAt`, `ParentId` FROM `Areas` AS `Area` 
WHERE `Area`.`id` = '[object Object]' AND `Area`.`slug` = 'Nakyal-1';*

This part is not correct:

WHERE `Area`.`id` = '[object Object]' 

What am I doing wrong?

Upvotes: 7

Views: 10690

Answers (1)

Eggon
Eggon

Reputation: 2356

I don't know if it is your case, but I had problems using shortcut '$' operators from sequelize. You might try this approach:

const Op = require('sequelize').Op;
***
where: { id: { [Op.ne]: Id }... }

Upvotes: 10

Related Questions