egg-mysql update 怎么指定查询条件
发布于 7 年前 作者 lpbird 6317 次浏览 来自 问答

45EAE2F2-C0CB-4568-811A-0F77F4AA5431.png 官方文档上默认的查询的key 是id , 而且查询条件和更改的colums放在一起 我觉得很奇怪,而且我试过了 如果一个表的主键是user_id 不是id 时就会报错 请各位指教

4 回复

同样遇到过这个问题,于是翻了 source :

proto.update = function* (table, row, options) {
  // ......
  if (!options.where) {
    if (!('id' in row)) {
      throw new Error('Can\'t not auto detect update condition, please set options.where, or make sure obj.id exists');
    }
    options.where = {
      id: row.id,
    };
  }
  // ......

可以看到,update 时主键必须指定且只能为 id

哈哈哈,顺便还发现 error message 写错了:Can’t not … (笑)

@dreamswhite 哈哈😄,我已经用了query的方法直接写sql语句,他这个封装真的不是很好用

回到顶部