@@ -252,6 +252,7 @@ export class ObjectDetailComponent implements OnInit {
252252 this . setColumnsToAdd ( )
253253 this . setAddPkColumnList ( )
254254 this . setPkOrder ( )
255+ this . setSrcPkOrder ( )
255256 this . setPkRows ( )
256257 this . setFkRows ( )
257258 this . setCCRows ( )
@@ -808,7 +809,9 @@ export class ObjectDetailComponent implements OnInit {
808809 spArr . sort ( ( a , b ) => {
809810 return a . spOrder - b . spOrder
810811 } )
811-
812+ srcArr . sort ( ( a , b ) => {
813+ return a . srcOrder - b . srcOrder
814+ } )
812815 for ( let i = 0 ; i < Math . min ( srcArr . length , spArr . length ) ; i ++ ) {
813816 this . pkArray . push (
814817 new FormGroup ( {
@@ -1092,6 +1095,7 @@ export class ObjectDetailComponent implements OnInit {
10921095 } )
10931096 this . pkData [ index ] . spOrder = newColumnOrder
10941097 this . setAddPkColumnList ( )
1098+ this . setSrcPkOrder ( )
10951099 this . setPkRows ( )
10961100 }
10971101
@@ -1113,23 +1117,9 @@ export class ObjectDetailComponent implements OnInit {
11131117 }
11141118
11151119 setPkOrder ( ) {
1116- if (
1117- this . currentObject &&
1118- this . conv . SpSchema [ this . currentObject ! . id ] ?. PrimaryKeys . length == this . pkData . length
1119- ) {
1120- this . pkData . forEach ( ( pk : IColumnTabData , i : number ) => {
1121- if (
1122- this . pkData [ i ] . spId === this . conv . SpSchema [ this . currentObject ! . id ] . PrimaryKeys [ i ] . ColId
1123- ) {
1124- this . pkData [ i ] . spOrder = this . conv . SpSchema [ this . currentObject ! . id ] . PrimaryKeys [ i ] . Order
1125- } else {
1126- let index = this . conv . SpSchema [ this . currentObject ! . id ] . PrimaryKeys . map (
1127- ( item ) => item . ColId
1128- ) . indexOf ( pk . spId )
1129- pk . spOrder = this . conv . SpSchema [ this . currentObject ! . id ] . PrimaryKeys [ index ] ?. Order
1130- }
1131- } )
1132- } else {
1120+ if ( ! this . currentObject || ! this . conv . SrcSchema [ this . currentObject ! . id ] ?. PrimaryKeys ) {
1121+ return ; // Early exit if there's no current object or primary key data
1122+ }
11331123 this . pkData . forEach ( ( pk : IColumnTabData , i : number ) => {
11341124 let index = this . conv . SpSchema [ this . currentObject ! . id ] ?. PrimaryKeys . map (
11351125 ( item ) => item . ColId
@@ -1138,9 +1128,21 @@ export class ObjectDetailComponent implements OnInit {
11381128 pk . spOrder = this . conv . SpSchema [ this . currentObject ! . id ] ?. PrimaryKeys [ index ] . Order
11391129 }
11401130 } )
1141- }
11421131 }
11431132
1133+ setSrcPkOrder ( ) {
1134+ if ( ! this . currentObject || ! this . conv . SrcSchema [ this . currentObject ! . id ] ?. PrimaryKeys ) {
1135+ return ; // Early exit if there's no current object or primary key data
1136+ }
1137+ const srcPrimaryKeys = this . conv . SrcSchema [ this . currentObject ! . id ] . PrimaryKeys ;
1138+ this . pkData . forEach ( ( pk : IColumnTabData ) => {
1139+ let index = srcPrimaryKeys . map ( item => item . ColId ) . indexOf ( pk . srcId ) ;
1140+ if ( index !== - 1 ) {
1141+ pk . srcOrder = srcPrimaryKeys [ index ] . Order ;
1142+ }
1143+ } ) ;
1144+ }
1145+
11441146 pkOrderValidation ( ) {
11451147 let arr = this . pkData
11461148 . filter ( ( column : IColumnTabData ) => {
@@ -1204,6 +1206,7 @@ export class ObjectDetailComponent implements OnInit {
12041206 this . pkData = this . conversion . getPkMapping ( this . tableData )
12051207 this . setAddPkColumnList ( )
12061208 this . setPkOrder ( )
1209+ this . setSrcPkOrder ( )
12071210 this . setPkRows ( )
12081211 this . isPkEditMode = false
12091212 } else {
0 commit comments