improved docs
This commit is contained in:
parent
adb8edb323
commit
004974d44d
|
@ -578,13 +578,13 @@ affected, err := engine.Id(id).Update(user)
|
||||||
|
|
||||||
这里需要注意,Update会自动从user结构体中提取非0和非nil得值作为需要更新的内容,因此,如果需要更新一个值为0,则此种方法将无法实现,因此有两种选择:
|
这里需要注意,Update会自动从user结构体中提取非0和非nil得值作为需要更新的内容,因此,如果需要更新一个值为0,则此种方法将无法实现,因此有两种选择:
|
||||||
|
|
||||||
1. 通过添加Cols函数指定需要更新结构体中的哪些值,未指定的将不更新,指定了的即使为0也会更新。
|
* 1.通过添加Cols函数指定需要更新结构体中的哪些值,未指定的将不更新,指定了的即使为0也会更新。
|
||||||
|
|
||||||
```Go
|
```Go
|
||||||
affected, err := engine.Id(id).Cols("age").Update(&user)
|
affected, err := engine.Id(id).Cols("age").Update(&user)
|
||||||
```
|
```
|
||||||
|
|
||||||
2. 通过传入map[string]interface{}来进行更新,但这时需要额外指定更新到哪个表,因为通过map是无法自动检测更新哪个表的。
|
* 2.通过传入map[string]interface{}来进行更新,但这时需要额外指定更新到哪个表,因为通过map是无法自动检测更新哪个表的。
|
||||||
|
|
||||||
```Go
|
```Go
|
||||||
affected, err := engine.Table(new(User)).Id(id).Update(map[string]interface{}{"age":0})
|
affected, err := engine.Table(new(User)).Id(id).Update(map[string]interface{}{"age":0})
|
||||||
|
|
Loading…
Reference in New Issue