在 Sequelize - ORM Node JS 中
在使用 like
运算符搜索特定元素时使用 enum
和 integer
字段会给出错误:
No operator matches the given name and argument type(s). You might need to add explicit type casts.
我如何需要为 integer
和 enum
字段键入类型转换?
我在查询job.status
的where Condition 是一个enum
字段
whereCondn = {
$or:[
{
'$job.jobReferenceId$': {
$iLike: (search ? search: '')
}
},
{
'$job.jobTitle$': {
$iLike: '%'+(search ? search: '')+'%'
}
},
{
'$job.experienceLevel$': {
$iLike: '%'+(search ? search: '')+'%'
}
},
{
'$job.location$': {
$iLike: '%'+(search ? search: '')+'%'
}
},
{
'$job.status$': {
$like: '%'+(search ? search: '')+'%'
}
},
{
'$job->hospital.name$':{
$iLike: '%'+(search ? search: '')+'%'
}
},
{
'$job->grade.gradeName$':{
$iLike: '%'+(search ? search: '')+'%'
}
},
{
'$job->speciality.specialityName$':{
$iLike: '%'+(search ? search: '')+'%'
}
},
{
'$job->specialityService.serviceName$':{
$iLike: '%'+(search ? search: '')+'%'
}
}
],
$and :[
{
'$job.draft$' : false
},
{
'doctorId' : bodyInput['doctorId']
}
]
};
}
最佳答案
对于像我一样访问此页面的其他人:
你可以这样使用 Sequelize.literal -
...
where: Sequelize.literal(`"job"."status"::TEXT LIKE '%${searchKeyword}%'`)),
...
关于javascript - Sequelize - Node Js - 枚举和整数字段搜索选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50501247/