在MySQL(和其他dbs)中,you can do a where in query with multiple columns如下所示:
SELECT * FROM trains WHERE (name, location) IN (('train1', 'us'), ... ,('train2', 'us'));
我正在尝试用sequelize:
const selectTrains = [
{name: 'train1', location: 'us'},
{name: 'train1', location: 'eu'},
{name: 'train2', location: 'us'},
];
let dbTrains = await Trains.findAll({ where: { [Op.in]: selectTrains} });
但是我收到以下错误:
UnhandledPromiseRejectionWarning:错误:值无效{name:'train1',location:'us'}
文档并未真正涵盖此用例。这可能与Op.in
运算符有关吗?
答案 0 :(得分:0)
您可以使用$or
实现相同的目标:
const selectTrains = [
{name: 'train1', location: 'us'},
{name: 'train1', location: 'eu'},
{name: 'train2', location: 'us'},
];
Trains.findAll({ where: { $or : selectTrains} });