Sequelize:为什么这个或不起作用?

时间:2016-10-31 09:21:58

标签: sequelize.js

这有效:

        var args = {fromID: 1, toID: 2};
        var altArgs = {};
        altArgs.fromID = args.toID;
        altArgs.toID = args.fromID;
        var ret = connectors.IM.findAll({ $or: [args, altArgs] }).then((res) => res.map((item) => item.dataValues));

但是这并不是,即使在$或语法方面,它看起来与我完全相同:

        const {fromID, toID} = args;
        var fromArgs = {};
        var toArgs = {};
        fromArgs.userID = fromID;
        toArgs.userID = toID;

        var ret = connectors.myUserData.findAll({ $or: [fromArgs, toArgs] }).then((res) => res.map((item) => item.dataValues));

myUserData包含一个userID字段,我要查找的值可以在表中找到。什么阻止第二个代码块工作?

1 个答案:

答案 0 :(得分:0)

错过了道具:.findAll({where: { $or: [fromArgs, toArgs]}})