mirror of https://github.com/go-gorm/gorm.git
Cache model struct with struct type
This commit is contained in:
parent
9b355ee86c
commit
1ba5ce3bbc
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue