我正在尝试像在 MySQL 语句中那样在 SequelizeJS 中使用 $in 运算符:
SELECT column_name(s)
FROM table_name
WHERE column_name IN (value1, value2, ...);
就我而言,我加入了三个表,但我认为这与问题无关。我不断收到此错误 Error: Invalid value { '$in': ['12345','67890','15948'] }
代码如下:
definedTable.findAll({
include: [{
model: definedTableTwo,
where: {
zip_code: {
$in: ['12345','67890','15948']
}
},
required: true,
plain: true
},
{
model: definedTableThree,
required: true,
plain: true
}]
})
有人可以提供一些有关如何使用 $in 运算符的见解吗?我见过的唯一示例是在搜索 ID 时在数组中使用整数。
最佳答案
只需阅读此处的文档 Sequelize WHERE
我会尝试:
const Op = Sequelize.Op;
definedTable.findAll({
include: [{
model: definedTableTwo,
where: {
zip_code: {
[Op.in]: ['12345','67890','15948']
}
},
required: true,
plain: true
},
{
model: definedTableThree,
required: true,
plain: true
}]
})
这有帮助吗?
关于javascript - 如何在 SequelizeJS 中使用 $in 运算符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49700623/