Mysql:sequlize query returns empty result

iam batman Source

Here is my raw query

select * from USER where concat_ws(' ',firstName,lastName) 
like '%ammu sudev%' OR email LIKE "%ammu sudev%"

Sequlize query

Users.findAll({
    where: {
        $or: [
        Sequelize.where(Sequelize.fn('concat_ws', Sequelize.col('firstName'), ' ', Sequelize.col('lastName')), {
            like: '%' + keyword + '%'
        }),
            { email: { $like: '%' + keyword + '%' } },
            { company: { $like: '%' + keyword+ '%' } }
        ]
    }
}).then((result)=>{
    console.log("Query",result);
    callback(result);
}).catch((error)=>{
    console.log("Error",error);
    callback(false);
})

But it returns the empty result however the row query returns the proper result

javascriptmysqlnode.jssequelize.js

Answers

answered 6 months ago Vivek Doshi #1

I think you need to change this line

like: '%' + keyword + '%'

to

$like: '%' + keyword + '%'

Within Sequelize.where .

comments powered by Disqus