我有一个模型“摘录”,并且想要获取不属于给定用户且不在排除摘录列表中的所有摘录(例如,列表中没有带有 id 的摘录 [0 , 1, 2, 3])。
我已成功选择了不属于用户的所有摘录,方法是:
Excerpt
.query({
whereNot: { owner_id : req.currentUser.id }
})
.fetchAll()
.then((excerptResults) => {
res.status(200).json(excerptResults);
});
并且我尝试使用 whereNotIn
排除具有以下代码段的摘录(按照 this stackoverflow post ):
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);
});
不幸的是,我收到以下错误消息
未处理的拒绝错误:编译 SELECT 查询时检测到未定义的绑定(bind):从“摘录”中选择“摘录”。*,其中“[object Object]”不在 (?) 中
我不太明白错误消息。有人有什么想法吗?
最佳答案
它应该适合你的情况:
Excerpt.query(function(qb){
qb.where('id','not in', [0,1,2,3]).andWhere('owner_id','=',req.currentUser.id )
})
.fetchAll()
.then(...);
关于javascript - 使用 knex 和 Bookshelf 查询时如何同时使用 '<>' 和 'whereNotIn'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41936153/