squelize and sqlite concat two column and place conditional in where on that

Issue

this.User.findAll({
  attributes: ['id', [sequelize.literal("firstname || 
        ' ' || lastname "),"
        fullName "],"
        fullName "],where:  {
          fullName: {
            [Op.like]: '%' + searchData + "%"
          }
        }
      })

//SQLITE_ERROR: no such column: fullName

Solution

Use the same literal in Sequelize.where to achieve your goal:

this.User.findAll({
  attributes: ['id', [sequelize.literal("firstname || 
        ' ' || lastname "),"
        fullName "],"
        fullName "],
  where: Sequelize.where(sequelize.literal("firstname || 
        ' ' || lastname "), Op.like, '%' + searchData + '%')
      })

Answered By – Anatoly

Answer Checked By – Katrina (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.