Sails.js:水线或过滤器不工作
Sails.js : Waterline OR filter not working
我正在开发 sails.js app using default waterline。
我有一组类别和位置,如下所示。
var categoryOrFilter = [1,2,3];
var locationsOrFilter = [8,9,10];
我正在尝试在我的 model
上写一个 where
,它将过滤属于 categoryOrFilter
中至少一个 categories
的模型项目 AND 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
});
我正在开发 sails.js app using default waterline。
我有一组类别和位置,如下所示。
var categoryOrFilter = [1,2,3];
var locationsOrFilter = [8,9,10];
我正在尝试在我的 model
上写一个 where
,它将过滤属于 categoryOrFilter
中至少一个 categories
的模型项目 AND 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
});