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