Update Document

This commit is contained in:
Jinzhu 2015-08-30 07:28:05 +08:00
parent fc8f0e53c8
commit 8e415788d5
1 changed files with 26 additions and 20 deletions

View File

@ -45,7 +45,7 @@ http://godoc.org/github.com/jinzhu/gorm
- [Initialize Database](#initialize-database) - [Initialize Database](#initialize-database)
- [Migration](#migration) - [Migration](#migration)
- [Basic CRUD](#basic-crud) - [Basic CRUD](#basic-crud)
- [Create Record](#create-record) - [Create](#create-record)
- [Query](#query) - [Query](#query)
- [Query With Where (Plain SQL)](#query-with-where-plain-sql) - [Query With Where (Plain SQL)](#query-with-where-plain-sql)
- [Query With Where (Struct & Map)](#query-with-where-struct--map) - [Query With Where (Struct & Map)](#query-with-where-struct--map)
@ -1217,7 +1217,15 @@ db.Model(&User{}).RemoveIndex("idx_user_name")
## Default values ## Default values
If you have defined a default value in the `sql` tag (see the struct Animal above) the generated create/update SQl will ignore these fields if is set blank data. ```go
type Animal struct {
ID int64
Name string `sql:"default:'galeone'"`
Age int64
}
```
If you have defined a default value in the `sql` tag, the generated create SQl will ignore these fields if it is blank.
Eg. Eg.
@ -1225,7 +1233,7 @@ Eg.
db.Create(&Animal{Age: 99, Name: ""}) db.Create(&Animal{Age: 99, Name: ""})
``` ```
The generated query will be: The generated SQL will be:
```sql ```sql
INSERT INTO animals("age") values('99'); INSERT INTO animals("age") values('99');
@ -1286,5 +1294,3 @@ db.Where("email = ?", "x@example.org").Attrs(User{RegisteredIp: "111.111.111.111
## License ## License
Released under the [MIT License](https://github.com/jinzhu/gorm/blob/master/License). Released under the [MIT License](https://github.com/jinzhu/gorm/blob/master/License).
[![GoDoc](https://godoc.org/github.com/jinzhu/gorm?status.png)](http://godoc.org/github.com/jinzhu/gorm)