update cols #1025

Open
opened 2018-06-28 02:24:49 +00:00 by steven-yx · 1 comment
steven-yx commented 2018-06-28 02:24:49 +00:00 (Migrated from github.com)

这里需要注意,Update会自动从user结构体中提取非0和非nil得值作为需要更新的内容,因此,如果需要更新一个值为0,则此种方法将无法实现,因此有两种选择:
1.通过添加Cols函数指定需要更新结构体中的哪些值,未指定的将不更新,指定了的即使为0也会更新。
affected, err := engine.Id(id).Cols("age").Update(&user)

能否支持 某一字段强制更新 Cols("age") 结构体中其他非 0 null 的数据也更新

这里需要注意,Update会自动从user结构体中提取非0和非nil得值作为需要更新的内容,因此,如果需要更新一个值为0,则此种方法将无法实现,因此有两种选择: 1.通过添加Cols函数指定需要更新结构体中的哪些值,未指定的将不更新,指定了的即使为0也会更新。 affected, err := engine.Id(id).Cols("age").Update(&user) 能否支持 某一字段强制更新 Cols("age") 结构体中其他非 0 null 的数据也更新
engine.MustCols("age").Update
```Go engine.MustCols("age").Update ```
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#1025
No description provided.