Update documents

This commit is contained in:
Jinzhu 2016-03-08 12:14:16 +08:00
parent a4a7cad6ee
commit 5483a097fd

View File

@ -19,18 +19,17 @@
} }
``` ```
* **Soft delete's default querying scope will only check `deleted_at IS NULL`** * **Soft Delete's default querying scope will only check `deleted_at IS NULL`**
Before `db.Find(&user)` will generate querying SQL if user has `DeletedAt` field Before it will check `deleted_at` less than `0001-01-02` also to exclude blank time, like:
`SELECT * FROM users WHERE deleted_at IS NULL OR deleted_at <= '0001-01-02'` `SELECT * FROM users WHERE deleted_at IS NULL OR deleted_at <= '0001-01-02'`
Now won't include blank time check `<= '0001-01-02` anymore, will generat SQL like: But it is not necessary if you are using type `*time.Time` for your model's `DeletedAt`, which has been used by `gorm.Model`, so below SQl is enough
`SELECT * FROM users WHERE deleted_at IS NULL` `SELECT * FROM users WHERE deleted_at IS NULL`
So your application's `DeletedAt` field should not use `time.Time` as data type, need to use pointer `*time.Time` or something like `NullTime`. So if you are using `gorm.Model`, then you are good, nothing need to be change, just make sure all records having blank time for `deleted_at` set to `NULL`, sample migrate script:
If you are using `gorm.Model`, then you are good, nothing need to be change, just make sure all records using blank time for `deleted_at` has been set to NULL, sample migration script:
```go ```go
import ( import (
@ -49,6 +48,12 @@
Before when GORM convert Struct, Field's name to db name, only those common initialisms from [golint](https://github.com/golang/lint/blob/master/lint.go#L702) like `HTTP`, `URI` are special handled. Before when GORM convert Struct, Field's name to db name, only those common initialisms from [golint](https://github.com/golang/lint/blob/master/lint.go#L702) like `HTTP`, `URI` are special handled.
So field `HTTP`'s db name will be `http` not `h_t_t_p`, but some other initialisms like `SKU` that not in golint, it's db name will be `s_k_u`, this release fixed this, any upper case initialisms should be converted correctly. So field `HTTP`'s db name will be `http` not `h_t_t_p`, but some other initialisms like `SKU` that not in golint, it's db name will be `s_k_u`, which looks ugly, this release fixed this, any upper case initialisms should be converted correctly.
If your applications using some upper case initialisms which doesn't exist in [golint](https://github.com/golang/lint/blob/master/lint.go#L702), you need to overwrite generated column name with tag, like `sql:"column:s_k_u"`, or alert your database's column name according to new logic If your applications using some upper case initialisms which doesn't exist in [golint](https://github.com/golang/lint/blob/master/lint.go#L702), you need to overwrite default column name with tag, like `gorm:"column:s_k_u"`, or alert your database's column name according to new logic
* Error `RecordNotFound` has been renamed to `ErrRecordNotFound`
* `mssql` driver has been moved out from default drivers, import it with `import _ "github.com/jinzhu/gorm/dialects/mssql"`
* `Hstore` has been moved to package `github.com/jinzhu/gorm/dialects/postgres`