Cache model struct with struct type

This commit is contained in:
Jinzhu 2015-02-18 08:47:44 +08:00
parent 9b355ee86c
commit 1ba5ce3bbc
1 changed files with 10 additions and 7 deletions

View File

@ -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
}