sequelize 和 sqlite concat 两列并在其中放置条件
squelize and sqlite concat two column and place conditional in where on that
this.User.findAll({
attributes: ['id', [sequelize.literal("firstname ||
' ' || lastname "),"
fullName "],"
fullName "],where: {
fullName: {
[Op.like]: '%' + searchData + "%"
}
}
})
//SQLITE_ERROR: 没有这样的列: fullName
在 Sequelize.where
中使用相同的文字来实现您的目标:
this.User.findAll({
attributes: ['id', [sequelize.literal("firstname ||
' ' || lastname "),"
fullName "],"
fullName "],
where: Sequelize.where(sequelize.literal("firstname ||
' ' || lastname "), Op.like, '%' + searchData + '%')
})
this.User.findAll({
attributes: ['id', [sequelize.literal("firstname ||
' ' || lastname "),"
fullName "],"
fullName "],where: {
fullName: {
[Op.like]: '%' + searchData + "%"
}
}
})
//SQLITE_ERROR: 没有这样的列: fullName
在 Sequelize.where
中使用相同的文字来实现您的目标:
this.User.findAll({
attributes: ['id', [sequelize.literal("firstname ||
' ' || lastname "),"
fullName "],"
fullName "],
where: Sequelize.where(sequelize.literal("firstname ||
' ' || lastname "), Op.like, '%' + searchData + '%')
})