From 1ba5ce3bbce70623be21f3429e5c80648b05d96d Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Wed, 18 Feb 2015 08:47:44 +0800 Subject: [PATCH] Cache model struct with struct type --- model_struct.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/model_struct.go b/model_struct.go index 7d196e6e..adfa776f 100644 --- a/model_struct.go +++ b/model_struct.go @@ -123,18 +123,17 @@ func (scope *Scope) GetModelStruct() *ModelStruct { } scopeType := reflectValue.Type() - if scope.db != nil { - if value, ok := scope.db.parent.ModelStructs[scopeType]; ok { - return value - } else { - scope.db.parent.ModelStructs[scopeType] = &modelStruct - } - } if scopeType.Kind() == reflect.Ptr { scopeType = scopeType.Elem() } + if scope.db != nil { + if value, ok := scope.db.parent.ModelStructs[scopeType]; ok { + return value + } + } + if scopeType.Kind() != reflect.Struct { return &modelStruct } @@ -303,6 +302,10 @@ func (scope *Scope) GetModelStruct() *ModelStruct { } } + if scope.db != nil { + scope.db.parent.ModelStructs[scopeType] = &modelStruct + } + return &modelStruct }