@@ -703,7 +703,14 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
703703 const targetResourcePkFields = { } ;
704704 const pksUniques = { } ;
705705 col . foreignResource . polymorphicResources . forEach ( ( pr ) => {
706- targetResources [ pr . whenValue ] = this . adminforth . config . resources . find ( ( res ) => res . resourceId == pr . resourceId ) ;
706+ if ( pr . resourceId === null ) {
707+ return ;
708+ }
709+ const targetResource = this . adminforth . config . resources . find ( ( res ) => res . resourceId == pr . resourceId ) ;
710+ if ( ! targetResource ) {
711+ return ;
712+ }
713+ targetResources [ pr . whenValue ] = targetResource ;
707714 targetConnectors [ pr . whenValue ] = this . adminforth . connectors [ targetResources [ pr . whenValue ] . dataSource ] ;
708715 targetResourcePkFields [ pr . whenValue ] = targetResources [ pr . whenValue ] . columns . find ( ( col ) => col . primaryKey ) . name ;
709716 const pksUnique = [ ...new Set ( data . data . filter ( ( item ) => item [ col . foreignResource . polymorphicOn ] === pr . whenValue ) . map ( ( item ) => item [ col . name ] ) ) ] ;
@@ -747,6 +754,13 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
747754
748755 data . data . forEach ( ( item ) => {
749756 item [ col . name ] = targetDataMap [ item [ col . name ] ] ;
757+
758+ if ( ! item [ col . name ] ) {
759+ const systemResource = col . foreignResource . polymorphicResources . find ( pr => pr . resourceId === null ) ;
760+ if ( systemResource ) {
761+ item [ col . foreignResource . polymorphicOn ] = systemResource . whenValue ;
762+ }
763+ }
750764 } ) ;
751765 } )
752766 ) ;
@@ -819,7 +833,7 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
819833 return { error : `Column '${ column } ' in resource '${ resourceId } ' is not a foreign key` } ;
820834 }
821835
822- const targetResourceIds = columnConfig . foreignResource . resourceId ? [ columnConfig . foreignResource . resourceId ] : columnConfig . foreignResource . polymorphicResources . map ( ( pr ) => pr . resourceId ) ;
836+ const targetResourceIds = columnConfig . foreignResource . resourceId ? [ columnConfig . foreignResource . resourceId ] : columnConfig . foreignResource . polymorphicResources . filter ( pr => pr . resourceId !== null ) . map ( ( pr ) => pr . resourceId ) ;
823837 const targetResources = targetResourceIds . map ( ( trId ) => this . adminforth . config . resources . find ( ( res ) => res . resourceId == trId ) ) ;
824838
825839 const responses = ( await Promise . all (
@@ -974,7 +988,14 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
974988 const targetConnectors = { } ;
975989 const targetResourcePkFields = { } ;
976990 column . foreignResource . polymorphicResources . forEach ( ( pr ) => {
977- targetResources [ pr . whenValue ] = this . adminforth . config . resources . find ( ( res ) => res . resourceId == pr . resourceId ) ;
991+ if ( pr . resourceId === null ) {
992+ return ;
993+ }
994+ const targetResource = this . adminforth . config . resources . find ( ( res ) => res . resourceId == pr . resourceId ) ;
995+ if ( ! targetResource ) {
996+ return ;
997+ }
998+ targetResources [ pr . whenValue ] = targetResource ;
978999 targetConnectors [ pr . whenValue ] = this . adminforth . connectors [ targetResources [ pr . whenValue ] . dataSource ] ;
9791000 targetResourcePkFields [ pr . whenValue ] = targetResources [ pr . whenValue ] . columns . find ( ( col ) => col . primaryKey ) . name ;
9801001 } ) ;
@@ -1062,7 +1083,14 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
10621083 const targetConnectors = { } ;
10631084 const targetResourcePkFields = { } ;
10641085 column . foreignResource . polymorphicResources . forEach ( ( pr ) => {
1065- targetResources [ pr . whenValue ] = this . adminforth . config . resources . find ( ( res ) => res . resourceId == pr . resourceId ) ;
1086+ if ( pr . resourceId === null ) {
1087+ return ;
1088+ }
1089+ const targetResource = this . adminforth . config . resources . find ( ( res ) => res . resourceId == pr . resourceId ) ;
1090+ if ( ! targetResource ) {
1091+ return ;
1092+ }
1093+ targetResources [ pr . whenValue ] = targetResource ;
10661094 targetConnectors [ pr . whenValue ] = this . adminforth . connectors [ targetResources [ pr . whenValue ] . dataSource ] ;
10671095 targetResourcePkFields [ pr . whenValue ] = targetResources [ pr . whenValue ] . columns . find ( ( col ) => col . primaryKey ) . name ;
10681096 } ) ;
0 commit comments