【发布时间】:2020-10-26 16:02:12
【问题描述】:
我有两个表,类别和子类别
都有描述字段
我配置了以下查询
const get = (req, res) => {
app.db({ s: 'subCategory', c: 'category' })
.select('s.id', 's.description', { category: 'c.description' })
.whereRaw('?? = ??', ['c.id', 's.categoryId'])
.where({ deletedAt: null })
.then(subCategorys => res.json(subCategorys))
.catch(err => res.status(500).send(err))
}
我重命名了类别列描述字段, 但它显示了重复列的错误,我有另一种方法,我以这种方式重命名并且它适用于那些具有相同名称的列,它显示错误 42702(这是列的模棱两可的错误)
我正在使用 postgresql 并将 knex 重命名为 db
这个方法有什么需要改变的,否则我真的需要用 knex.raw 创建整个查询?
错误: { "length": 111, "name": "error", "severity": "ERROR", "code": "42702", "position": "152", "file": "parse_relation.c", "line": "791", "routine": "colNameToVar" }
【问题讨论】:
-
用表别名限定所有列名(如
deletedat)。 -
你是对的,我添加了
.whereNull('s.deletedAt'),它成功了非常感谢你
标签: postgresql knex.js