1

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.

1 Answer 1

1

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 
Sign up to request clarification or add additional context in comments.

1 Comment

In the database design the field can have empty string, It can't have NULL. But if I could change it to NULL instead of empty string, the question remains. How to query an empty string in Sequelize.js

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.