【发布时间】:2017-01-30 21:24:41
【问题描述】:
我有一个模型,“摘录”,并且想要获取所有不属于给定用户所有的摘录,并且不在排除摘录列表中(例如,列表中没有带有 id 的摘录 [0 , 1, 2, 3]).
我已经成功地选择了所有不属于用户的摘录,方法是:
Excerpt
.query({
whereNot: { owner_id : req.currentUser.id }
})
.fetchAll()
.then((excerptResults) => {
res.status(200).json(excerptResults);
});
我尝试使用whereNotIn 排除带有以下sn-p 的摘录(根据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);
});
很遗憾,我收到以下错误消息
Unhandled rejection Error: Undefined binding(s) detected when compiling SELECT query: select "excerpts".* from "excerpts" where "[object Object]" not in (?)
我不太明白错误信息。有人有什么想法吗?
【问题讨论】:
-
试试
Excerpt.whereNotIn('id', [0, 1, 2, 3]) -
@MukeshSharma 我刚刚收到错误消息
Unhandled rejection TypeError: _excerpts2.default.whereNotIn is not a function
标签: javascript node.js knex.js bookshelf.js