【问题标题】:Sails.js : Waterline OR filter not workingSails.js:水线或过滤器不起作用
【发布时间】:2015-06-11 04:13:19
【问题描述】:

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

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

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

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

我的模型如下图。

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 值完美运行。

我做错了什么?

【问题讨论】:

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


    【解决方案1】:

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

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

    【讨论】:

    • 完美!那是生命的救星。
    猜你喜欢
    • 2015-06-11
    • 2018-01-12
    • 2017-01-01
    • 2015-12-14
    • 2014-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-16
    相关资源
    最近更新 更多