MustCols+Update+AutoCond时有错。 #1797

Open
opened 2020-09-16 15:45:17 +00:00 by RelicOfTesla · 2 comments
db.MustCols("last_error").Update(tbl_task_record.Row{
		LastError: "",
	}, tbl_task_record.Row{
		Id: 4,
	})

想要清空error信息,结果清空不了,多出了 where AND last_error=''

具体为 UPDATE task_record SET last_error = '' WHERE id=4 AND last_error=''

如果使用.NoAutoCondition(true)的话,到是生成对了,但是就无法使用updated/version tag了。

```go db.MustCols("last_error").Update(tbl_task_record.Row{ LastError: "", }, tbl_task_record.Row{ Id: 4, }) ``` 想要清空error信息,结果清空不了,多出了 where AND last_error='' 具体为 UPDATE task_record SET last_error = '' WHERE id=4 AND last_error='' 如果使用.NoAutoCondition(true)的话,到是生成对了,但是就无法使用updated/version tag了。
Author

需要注意的,如果不使用Update(..., condBean)的话,而是直接使用Where().Update()是没问题的。

db.MustCols("last_error").Where("id=4").Update(tbl_task_record.Row{
		LastError: "",
	})
 // UPDATE task_record SET last_error = '' WHERE id=4

建议重新梳理下update(..., condBean)中的condBean逻辑。。

#1784 工单的两个问题,也是类似,用起来不太正常。

需要注意的,如果不使用Update(..., condBean)的话,而是直接使用Where().Update()是没问题的。 即 ```go db.MustCols("last_error").Where("id=4").Update(tbl_task_record.Row{ LastError: "", }) // UPDATE task_record SET last_error = '' WHERE id=4 ``` 建议重新梳理下update(..., condBean)中的condBean逻辑。。 #1784 工单的两个问题,也是类似,用起来不太正常。
Author

另外用Cols()有坑,当使用了的用Cols时候,只会更新bean的Cols(...)和tag字段,不会更新其他字段。所以没法用Cols()...所以跑去用MustCols了。。。所以还是有坑。。。

另外用Cols()有坑,当使用了的用Cols时候,只会更新bean的Cols(...)和tag字段,不会更新其他字段。所以没法用Cols()...所以跑去用MustCols了。。。所以还是有坑。。。
lunny added the
kind
bug
label 2021-06-12 08:40:12 +00:00
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: xorm/xorm#1797
No description provided.