Fix can't load preload fields correctly
This commit is contained in:
parent
198fc47051
commit
37bf87aa29
7
field.go
7
field.go
@ -56,11 +56,11 @@ func (field *Field) Set(value interface{}) error {
|
|||||||
func (scope *Scope) Fields() map[string]*Field {
|
func (scope *Scope) Fields() map[string]*Field {
|
||||||
if scope.fields == nil {
|
if scope.fields == nil {
|
||||||
fields := map[string]*Field{}
|
fields := map[string]*Field{}
|
||||||
structFields := scope.GetStructFields()
|
modelStruct := scope.GetModelStruct()
|
||||||
|
|
||||||
indirectValue := scope.IndirectValue()
|
indirectValue := scope.IndirectValue()
|
||||||
isStruct := indirectValue.Kind() == reflect.Struct
|
isStruct := indirectValue.Kind() == reflect.Struct
|
||||||
for _, structField := range structFields {
|
for _, structField := range modelStruct.StructFields {
|
||||||
if isStruct {
|
if isStruct {
|
||||||
fields[structField.DBName] = getField(indirectValue, structField)
|
fields[structField.DBName] = getField(indirectValue, structField)
|
||||||
} else {
|
} else {
|
||||||
@ -68,8 +68,11 @@ func (scope *Scope) Fields() map[string]*Field {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if modelStruct.cached {
|
||||||
scope.fields = fields
|
scope.fields = fields
|
||||||
}
|
}
|
||||||
|
return fields
|
||||||
|
}
|
||||||
return scope.fields
|
return scope.fields
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ type ModelStruct struct {
|
|||||||
StructFields []*StructField
|
StructFields []*StructField
|
||||||
ModelType reflect.Type
|
ModelType reflect.Type
|
||||||
defaultTableName string
|
defaultTableName string
|
||||||
|
cached bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s ModelStruct) TableName(db *DB) string {
|
func (s ModelStruct) TableName(db *DB) string {
|
||||||
@ -372,6 +373,7 @@ func (scope *Scope) GetModelStruct() *ModelStruct {
|
|||||||
modelStructs[scopeType] = &modelStruct
|
modelStructs[scopeType] = &modelStruct
|
||||||
|
|
||||||
<-finished
|
<-finished
|
||||||
|
modelStruct.cached = true
|
||||||
|
|
||||||
return &modelStruct
|
return &modelStruct
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user