@@ -941,15 +941,17 @@ export class AppSyncModelVisitor<
941
941
} else if ( connectionInfo . kind === CodeGenConnectionType . HAS_ONE ) {
942
942
if ( isCustomPKEnabled ) {
943
943
const connectedModelFields = getModelPrimaryKeyComponentFields ( connectionInfo . connectedModel ) ;
944
- connectionInfo . targetNames . forEach ( ( target , index ) => {
945
- addFieldToModel ( model , {
946
- name : target ,
947
- directives : [ ] ,
948
- type : connectedModelFields [ index ] . type ,
949
- isList : false ,
950
- isNullable : field . isNullable ,
944
+ if ( connectedModelFields ?. length > 0 ) {
945
+ connectionInfo . targetNames . forEach ( ( target , index ) => {
946
+ addFieldToModel ( model , {
947
+ name : target ,
948
+ directives : [ ] ,
949
+ type : connectedModelFields [ index ] . type ,
950
+ isList : false ,
951
+ isNullable : field . isNullable ,
952
+ } ) ;
951
953
} ) ;
952
- } ) ;
954
+ }
953
955
} else {
954
956
addFieldToModel ( model , {
955
957
name : connectionInfo . targetName ,
@@ -962,15 +964,17 @@ export class AppSyncModelVisitor<
962
964
} else if ( connectionInfo . kind === CodeGenConnectionType . BELONGS_TO ) {
963
965
if ( isCustomPKEnabled ) {
964
966
const connectedModelFields = getModelPrimaryKeyComponentFields ( connectionInfo . connectedModel ) ;
965
- connectionInfo . targetNames . forEach ( ( target , index ) => {
966
- addFieldToModel ( model , {
967
- name : target ,
968
- directives : [ ] ,
969
- type : connectedModelFields [ index ] . type ,
970
- isList : false ,
971
- isNullable : field . isNullable ,
967
+ if ( connectedModelFields ?. length > 0 ) {
968
+ connectionInfo . targetNames . forEach ( ( target , index ) => {
969
+ addFieldToModel ( model , {
970
+ name : target ,
971
+ directives : [ ] ,
972
+ type : connectedModelFields [ index ] . type ,
973
+ isList : false ,
974
+ isNullable : field . isNullable ,
975
+ } ) ;
972
976
} ) ;
973
- } ) ;
977
+ }
974
978
} else {
975
979
addFieldToModel ( model , {
976
980
name : connectionInfo . targetName ,
0 commit comments