mirror of https://github.com/go-gorm/gorm.git
Refactor handleHasManyPreload
This commit is contained in:
parent
4786e830d6
commit
0fd2fd66d5
|
@ -160,15 +160,10 @@ func (scope *Scope) handleHasManyPreload(field *Field, conditions []interface{})
|
||||||
preloadMap[toString(foreignValues)] = append(preloadMap[toString(foreignValues)], result)
|
preloadMap[toString(foreignValues)] = append(preloadMap[toString(foreignValues)], result)
|
||||||
}
|
}
|
||||||
|
|
||||||
objects := scope.IndirectValue()
|
for j := 0; j < indirectScopeValue.Len(); j++ {
|
||||||
for j := 0; j < objects.Len(); j++ {
|
object := indirect(indirectScopeValue.Index(j))
|
||||||
object := reflect.Indirect(objects.Index(j))
|
|
||||||
objectRealValue := getValueFromFields(object, relation.AssociationForeignFieldNames)
|
objectRealValue := getValueFromFields(object, relation.AssociationForeignFieldNames)
|
||||||
objectStringValue := toString(objectRealValue)
|
if results, ok := preloadMap[toString(objectRealValue)]; ok {
|
||||||
if results, ok := preloadMap[objectStringValue]; ok {
|
|
||||||
if object.Kind() == reflect.Ptr {
|
|
||||||
object = object.Elem()
|
|
||||||
}
|
|
||||||
f := object.FieldByName(field.Name)
|
f := object.FieldByName(field.Name)
|
||||||
f.Set(reflect.Append(f, results...))
|
f.Set(reflect.Append(f, results...))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue