Dan
Dan

Reputation: 1891

How to search column for empty string using Sequelize.js?

I have a variable called data.val. And a query to check if the value is inside my table. But it doesn't work if the variable is an empty string data.val=''.

How can I search for empty string in Sequelize.js????

My Sequelize query is:

models.table_data.findOne({
            where:{
                id_person:data.id_person,
                id_agr_data:data.id_agr_data,
                id_tram:data.id_tram,
                value:data.val
            }
        }).then(data_person=>{
            if(data_person){
                resolve(true);
            }else{
                resolve(false);         
            }
        }).catch(err=>{
            reject("ERROR");
        });

The problem is in value:data.val. When I have, for example a value 'A' in my table and data.val='A' it works. But when the variable is equal to empty string is like it doesn't search for the empty string.

Upvotes: 1

Views: 2638

Answers (1)

Vivek Doshi
Vivek Doshi

Reputation: 58603

I think the default value of value field in table must be null and not empty string

So you can change the query like :

value: data.val != '' ? data.val : null
// OR
Set the `value`'s default value empty string 

Upvotes: 1

Related Questions