Support specify GORM tag setting inside scanner

This commit is contained in:
Jinzhu 2016-08-25 17:59:26 +08:00
parent 35a2a004d8
commit f26fa242cc
2 changed files with 8 additions and 1 deletions

View File

@ -117,7 +117,7 @@ type Company struct {
}
type Role struct {
Name string
Name string `gorm:"size:256"`
}
func (role *Role) Scan(value interface{}) error {

View File

@ -188,6 +188,13 @@ func (scope *Scope) GetModelStruct() *ModelStruct {
if _, isScanner := fieldValue.(sql.Scanner); isScanner {
// is scanner
field.IsScanner, field.IsNormal = true, true
if indirectType.Kind() == reflect.Struct {
for i := 0; i < indirectType.NumField(); i++ {
for key, value := range parseTagSetting(indirectType.Field(i).Tag) {
field.TagSettings[key] = value
}
}
}
} else if _, isTime := fieldValue.(*time.Time); isTime {
// is time
field.IsNormal = true