node.js - 风 sails .js : Waterline OR filter not working

标签 node.js sails.js where-clause waterline

我正在开发一个sails.js应用程序使用默认 waterline .

我有一系列类别和位置,如下所示。

var categoryOrFilter = [1,2,3];
var locationsOrFilter = [8,9,10];

我正在尝试在我的model上编写一个where,它将过滤属于categoryOrFilter中至少一个categories的模型项并且至少属于locationsOrFilter中的一个locations

我的模型如下所示。

attributes: {

        category: {
            model: 'category'
        },

        location: {
            model: 'location'
        }

}

我已编写查询,如下所示。

 Model.find()
        .where({
            or: [{
                "category": categoryOrFilter
            }]
        })
        .where({
            or: [{
                "location": locationsOrFilter
            }]
        })
        .exec(function (err, modelItem) {
             //Some logic
        });

我的categoryOrFilter值没有被考虑。我的 locationOrFilter 值完美运行。

我做错了什么?

最佳答案

不需要第二个 where 和“or”,条件部分之间的默认运算符是 AND,对于单个条件部分中的数组元素,它是 IN

Model.find()
    .where({
            "category": categoryOrFilter,
            "location": locationsOrFilter
    })
    .exec(function (err, modelItem) {
         // Some logic
    }); 

关于node.js - 风 sails .js : Waterline OR filter not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30771458/

相关文章:

node.js - 如何解析以数组作为输入的 GraphQl 突变

javascript - 如何通过MongoDB中的特定变量findAll?

node.js - 如何更改 sails 中的图标?

javascript - sails js,示例代码如主页所示

MySql 无法连接到 sails lift 上的 Sailsjs

MySQL 查询要过滤的多列?

node.js - Node - GraphQL - Ad.user 字段类型必须是输出类型,但得到 : undefined

node.js - 从 Bot Framework botbuilder 开始并收到断言错误

Swift - 为什么协议(protocol)仍然被视为通用的,即使 where 子句已经专门化了关联类型?

mysql - Where 子句不适用于 MySQL Select-Query 中的所有列