CNode

egg-mysql update 怎么指定查询条件

问答
Llpbird发布于9 年前最后回复9 年前4 回复7869 浏览0 收藏

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

查看回复

回复 (4)

D
dreamswhite#1·9 年前

同样遇到过这个问题,于是翻了 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

D
dreamswhite#2·9 年前

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

L
lpbird#3·9 年前
引用 dreamswhite哈哈哈,顺便还发现 error message 写错了:Can't not .... (笑)

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

A
atian25#4·9 年前

欢迎 PR

参与回复
登录后即可参与回复。登录