我在关系数据库中使用 Knex.js。目前正在尝试做一个相对简单的连接,不涉及别名。
knex('tools_users')
.select('*').from('tools_users')
.innerJoin('users', 'users.id', 'tools_users.user_id')
.innerJoin('tools', 'tools.id', 'tools_users.tool_id')
.where('users.id', userId)
.andWhere('tools.id', toolId)
.andWhere('tools_users.current_durability', '>', 0)
.first()
.decrement('tools_users.current_durability', durabilityUsed)
.then(() => {
console.log('tool updated');
})
.catch((err) => {
console.error(err);
});
Run Code Online (Sandbox Code Playgroud)
这console.error(err)会产生这个错误:error: missing FROM-clause entry for table "users"
我在网上其他地方找到的每个解决方案都表明这是别名问题。不过我没有使用任何别名。不知道还有什么可做的。我发现 github 存储库上的 knex 问题尚无定论。