@@ -121,10 +121,23 @@ func preloadEntryPoint(db *gorm.DB, joins []string, relationships *schema.Relati
121
121
}
122
122
} else if rel := relationships .Relations [name ]; rel != nil {
123
123
if joined , nestedJoins := isJoined (name ); joined {
124
- reflectValue := rel .Field .ReflectValueOf (db .Statement .Context , db .Statement .ReflectValue )
125
- tx := preloadDB (db , reflectValue , reflectValue .Interface ())
126
- if err := preloadEntryPoint (tx , nestedJoins , & tx .Statement .Schema .Relationships , preloadMap [name ], associationsConds ); err != nil {
127
- return err
124
+ switch rv := db .Statement .ReflectValue ; rv .Kind () {
125
+ case reflect .Slice , reflect .Array :
126
+ for i := 0 ; i < rv .Len (); i ++ {
127
+ reflectValue := rel .Field .ReflectValueOf (db .Statement .Context , rv .Index (i ))
128
+ tx := preloadDB (db , reflectValue , reflectValue .Interface ())
129
+ if err := preloadEntryPoint (tx , nestedJoins , & tx .Statement .Schema .Relationships , preloadMap [name ], associationsConds ); err != nil {
130
+ return err
131
+ }
132
+ }
133
+ case reflect .Struct :
134
+ reflectValue := rel .Field .ReflectValueOf (db .Statement .Context , rv )
135
+ tx := preloadDB (db , reflectValue , reflectValue .Interface ())
136
+ if err := preloadEntryPoint (tx , nestedJoins , & tx .Statement .Schema .Relationships , preloadMap [name ], associationsConds ); err != nil {
137
+ return err
138
+ }
139
+ default :
140
+ return gorm .ErrInvalidData
128
141
}
129
142
} else {
130
143
tx := db .Table ("" ).Session (& gorm.Session {Context : db .Statement .Context , SkipHooks : db .Statement .SkipHooks })
0 commit comments