我正在开发一个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/