Deepak Dev
Deepak Dev

Reputation: 101

Sequelize 'where in' automatically add single quotes to the IDs passed for where param

I want to get all the data from the table using 'where in' function of Seqalzie. But unfortunately, the number array is converted into a string which leads to false results.

Seqalazie code :

 mypromise(Requirement_idLists).then((res) => {  
        return res;
    })
    .then(async ids => {
        filteredIds = ids; // number array
        console.log(`Fetching Technologies` + filteredIds);
        return await SelectedTech.findAll({ where: { Requirement_id: [filteredIds] } })
       .then(async data => { 
            return data;
        });
    })

seqalize log:

 SELECT `Selected_tech_id`, `Requirement_id`, `Project_id`, `User_id`, `Technology`, 
`Technology_experience`, `Technology_level`, `Technology_version`, `Technology_id`, 
 `createdAt`, `updatedAt` FROM `SelectedTechnologiesTbs` AS `SelectedTechnologiesTbs` 
 WHERE `SelectedTechnologiesTbs`.`Requirement_id` IN ('1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16');

I want to get rid of single quote in this ('1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16')

Upvotes: 0

Views: 232

Answers (1)

Anf
Anf

Reputation: 26

Check if the "ids" is already an array. If it is, the "{ Requirement_id: [filteredIds]}" , should be [{ Requirement_id: filteredIds }].

Upvotes: 1

Related Questions