标签:class entry try turn dup this 清零 style LLC
如果把model先定义好变量,查询时用此变量,批量更新时就不能再用此变量了,会报重复ID错误。
解决办法是重新定义model变量,或直接this.model(‘xxx‘)。
以下为场景复原
const sql = `...` const model = this.model(‘xxx‘) const assertRecords = await model.where(condition).query(sql) if (!think.isEmpty(assertRecords)) { let willClearItems = assertRecords.map(e => { return { id: e.id, score: 0 } }) await model.updateMany(willClearItems) //批量清零 }
这样会报错:
{ Error: ER_DUP_ENTRY: Duplicate entry ‘94‘ for key ‘PRIMARY‘
最后句话改为
await this.model(‘xxx‘).updateMany(willClearItems) //批量清零
就可以批量修改了
标签:class entry try turn dup this 清零 style LLC
原文地址:https://www.cnblogs.com/yuanzheng/p/12893608.html