From f26fa242cc1bf884f9a4f98849f70fb8e73f441f Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Thu, 25 Aug 2016 17:59:26 +0800 Subject: [PATCH] Support specify GORM tag setting inside scanner --- migration_test.go | 2 +- model_struct.go | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/migration_test.go b/migration_test.go index 7fdf7bf8..30085263 100644 --- a/migration_test.go +++ b/migration_test.go @@ -117,7 +117,7 @@ type Company struct { } type Role struct { - Name string + Name string `gorm:"size:256"` } func (role *Role) Scan(value interface{}) error { diff --git a/model_struct.go b/model_struct.go index d6a71c0b..d9e84c3c 100644 --- a/model_struct.go +++ b/model_struct.go @@ -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