@@ -270,11 +270,15 @@ func preloadHasMany(tx *Connection, asoc *AssociationMetaInfo, mmi *ModelMetaInf
270270 asocValue := slice .Elem ().Index (i )
271271 if mmi .mapper .FieldByName (mvalue , "ID" ).Interface () == mmi .mapper .FieldByName (asocValue , foreignField .Path ).Interface () ||
272272 reflect .DeepEqual (mmi .mapper .FieldByName (mvalue , "ID" ), mmi .mapper .FieldByName (asocValue , foreignField .Path )) {
273- if modelAssociationField .Kind () == reflect .Slice || modelAssociationField .Kind () == reflect .Array {
273+
274+ switch {
275+ case modelAssociationField .Kind () == reflect .Slice || modelAssociationField .Kind () == reflect .Array :
274276 modelAssociationField .Set (reflect .Append (modelAssociationField , asocValue ))
275- continue
277+ case modelAssociationField .Kind () == reflect .Ptr :
278+ modelAssociationField .Elem ().Set (reflect .Append (modelAssociationField .Elem (), asocValue ))
279+ default :
280+ modelAssociationField .Set (asocValue )
276281 }
277- modelAssociationField .Set (asocValue )
278282 }
279283 }
280284 })
@@ -380,11 +384,15 @@ func preloadBelongsTo(tx *Connection, asoc *AssociationMetaInfo, mmi *ModelMetaI
380384 asocValue := slice .Elem ().Index (i )
381385 if mmi .mapper .FieldByName (mvalue , fi .Path ).Interface () == mmi .mapper .FieldByName (asocValue , "ID" ).Interface () ||
382386 reflect .DeepEqual (mmi .mapper .FieldByName (mvalue , fi .Path ), mmi .mapper .FieldByName (asocValue , "ID" )) {
383- if modelAssociationField .Kind () == reflect .Slice || modelAssociationField .Kind () == reflect .Array {
387+
388+ switch {
389+ case modelAssociationField .Kind () == reflect .Slice || modelAssociationField .Kind () == reflect .Array :
384390 modelAssociationField .Set (reflect .Append (modelAssociationField , asocValue ))
385- continue
391+ case modelAssociationField .Kind () == reflect .Ptr :
392+ modelAssociationField .Elem ().Set (asocValue )
393+ default :
394+ modelAssociationField .Set (asocValue )
386395 }
387- modelAssociationField .Set (asocValue )
388396 }
389397 }
390398 })
0 commit comments