@@ -71,24 +71,33 @@ public function generate(): array
7171 protected function handleParentReferences (TableDefinition $ tableDefinition ): array
7272 {
7373 $ sql = [];
74+ $ indexes = [];
7475 foreach ($ tableDefinition ->parentReferences as $ parentReference ) {
7576 $ parentTcaConfig = $ parentReference ->getTca ()['config ' ];
7677 // Generate indexes for the parent uid field for better performance.
7778 if (isset ($ parentTcaConfig ['foreign_field ' ])) {
7879 $ foreignField = $ parentTcaConfig ['foreign_field ' ];
79- $ sqlStatement = 'CREATE TABLE ` ' . $ tableDefinition ->table . '` (KEY parent_uid ( ' . $ foreignField . ')); ' ;
80- if (!in_array ($ sqlStatement , $ sql , true )) {
81- $ sql [] = $ sqlStatement ;
82- }
80+ $ indexes [$ tableDefinition ->table ][] = $ foreignField ;
81+ }
82+ if (isset ($ parentTcaConfig ['foreign_table_field ' ])) {
83+ $ foreignTableName = $ parentTcaConfig ['foreign_table_field ' ];
84+ $ indexes [$ tableDefinition ->table ][] = $ foreignTableName ;
8385 }
8486 // The foreign_match_fields fields are automatically added, so that feature "shareAcrossFields" works.
8587 foreach ($ parentTcaConfig ['foreign_match_fields ' ] ?? [] as $ foreignMatchField => $ foreignMatchValue ) {
88+ $ indexes [$ tableDefinition ->table ][] = $ foreignMatchField ;
8689 $ sqlStatement = 'CREATE TABLE ` ' . $ tableDefinition ->table . '` (` ' . $ foreignMatchField . '` varchar(255) DEFAULT \'\' NOT NULL); ' ;
8790 if (!in_array ($ sqlStatement , $ sql , true )) {
8891 $ sql [] = $ sqlStatement ;
8992 }
9093 }
9194 }
95+ foreach ($ indexes as $ table => $ indexFields ) {
96+ $ sqlStatement = 'CREATE TABLE ` ' . $ table . '` (KEY parent_uid ( ' . implode (', ' , $ indexFields ) . ')); ' ;
97+ if (!in_array ($ sqlStatement , $ sql , true )) {
98+ $ sql [] = $ sqlStatement ;
99+ }
100+ }
92101 return $ sql ;
93102 }
94103}
0 commit comments