@@ -245,25 +245,32 @@ func isStructType(data reflect.Value) bool {
245
245
(data .Kind () == reflect .Ptr && data .Elem ().Kind () == reflect .Struct )
246
246
}
247
247
248
- func pullRelationShip (cache map [string ]bool , relationships []* schema.Relationship ) []field.Relation {
248
+ func pullRelationShip (cache map [string ][]field. Relation , relationships []* schema.Relationship ) []field.Relation {
249
249
if len (relationships ) == 0 {
250
250
return nil
251
251
}
252
252
result := make ([]field.Relation , len (relationships ))
253
- for i , relationship := range relationships {
254
- var childRelations []field. Relation
253
+
254
+ for _ , relationship := range relationships {
255
255
varType := strings .TrimLeft (relationship .Field .FieldType .String (), "[]*" )
256
- if ! cache [varType ] {
257
- cache [varType ] = true
258
- childRelations = pullRelationShip (cache , append (append (append (append (
256
+ _ , ok := cache [varType ]
257
+ if ! ok {
258
+ cache [varType ] = []field.Relation {}
259
+ childRelations := pullRelationShip (cache , append (append (append (append (
259
260
make ([]* schema.Relationship , 0 , 4 ),
260
261
relationship .FieldSchema .Relationships .BelongsTo ... ),
261
262
relationship .FieldSchema .Relationships .HasOne ... ),
262
263
relationship .FieldSchema .Relationships .HasMany ... ),
263
264
relationship .FieldSchema .Relationships .Many2Many ... ),
264
265
)
266
+ cache [varType ] = childRelations
265
267
}
266
- result [i ] = * field .NewRelationWithType (field .RelationshipType (relationship .Type ), relationship .Name , varType , childRelations ... )
268
+ }
269
+
270
+ for i , relationship := range relationships {
271
+ varType := strings .TrimLeft (relationship .Field .FieldType .String (), "[]*" )
272
+ cached := cache [varType ]
273
+ result [i ] = * field .NewRelationWithType (field .RelationshipType (relationship .Type ), relationship .Name , varType , cached ... )
267
274
}
268
275
return result
269
276
}
0 commit comments