diff --git a/docs/QuickStart.md b/docs/QuickStart.md index dd1b2401..70bf9d23 100644 --- a/docs/QuickStart.md +++ b/docs/QuickStart.md @@ -382,6 +382,18 @@ user.Name = "myname" affected, err := engine.Id(id).Update(&user) ``` +这里需要注意,Update会自动从user结构体中提取非0和非nil得值作为需要更新的内容,因此,如果需要更新一个值为0,则此种方法将无法实现,因此有两种选择: + +1. 通过添加Cols函数指定需要更新结构体中的哪些值,未指定的将不更新,指定了的即使为0也会更新。 +```Go +affected, err := engine.Id(id).Cols("age").Update(&user) +``` + +2. 通过传入map[string]interface{}来进行更新,但这时需要额外指定更新到哪个表,因为通过map是无法自动检测更新哪个表的。 +```Go +affected, err := engine.Table(new(User)).Id(id).Update(map[string]interface{}{"age":0}) +``` + ## 8.删除数据