使用 knex 和 Bookshelf 查询时如何同时使用“<>”和 'whereNotIn'?
How do I use both a '<>' and a 'whereNotIn' when querying with knex and Bookshelf?
我有一个模型 'Excerpt',我想获取不属于给定用户且不在排除的摘录列表中的所有摘录 (例如,没有摘录id 来自列表 [0, 1, 2, 3]).
我已经成功地选择了所有不属于用户的摘录,方法是:
Excerpt
.query({
whereNot: { owner_id : req.currentUser.id }
})
.fetchAll()
.then((excerptResults) => {
res.status(200).json(excerptResults);
});
并且我尝试使用 whereNotIn
来排除带有以下代码段的摘录 (根据 ) :
Excerpt
.query({
whereNotIn: { id : [0, 1, 2, 3] }
})
.fetchAll()
.then((excerptResults) => {
var tasks = [];
for(var i=0; i<excerptResults.models.length; i++) {
tasks.push(excerptResults.models[i].attributes);
}
res.status(200).json(tasks);
});
不幸的是,我收到以下错误消息
Unhandled rejection Error: Undefined binding(s) detected when compiling SELECT query: select "excerpts".* from "excerpts" where "[object Object]" not in (?)
我不太明白错误信息。有人有什么想法吗?
它应该适合你的情况:
Excerpt.query(function(qb){
qb.where('id','not in', [0,1,2,3]).andWhere('owner_id','=',req.currentUser.id )
})
.fetchAll()
.then(...);
我有一个模型 'Excerpt',我想获取不属于给定用户且不在排除的摘录列表中的所有摘录 (例如,没有摘录id 来自列表 [0, 1, 2, 3]).
我已经成功地选择了所有不属于用户的摘录,方法是:
Excerpt
.query({
whereNot: { owner_id : req.currentUser.id }
})
.fetchAll()
.then((excerptResults) => {
res.status(200).json(excerptResults);
});
并且我尝试使用 whereNotIn
来排除带有以下代码段的摘录 (根据
Excerpt
.query({
whereNotIn: { id : [0, 1, 2, 3] }
})
.fetchAll()
.then((excerptResults) => {
var tasks = [];
for(var i=0; i<excerptResults.models.length; i++) {
tasks.push(excerptResults.models[i].attributes);
}
res.status(200).json(tasks);
});
不幸的是,我收到以下错误消息
Unhandled rejection Error: Undefined binding(s) detected when compiling SELECT query: select "excerpts".* from "excerpts" where "[object Object]" not in (?)
我不太明白错误信息。有人有什么想法吗?
它应该适合你的情况:
Excerpt.query(function(qb){
qb.where('id','not in', [0,1,2,3]).andWhere('owner_id','=',req.currentUser.id )
})
.fetchAll()
.then(...);