File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -243,7 +243,19 @@ protected function analyzePrimaryKey(array $columns)
243243 protected function analyzeForeignKeys (array &$ structure , string $ table ): void
244244 {
245245 $ lowerTable = strtolower ($ table );
246- foreach ($ this ->connection ->getSupplementalDriver ()->getForeignKeys ($ table ) as $ row ) {
246+
247+ $ foreignKeys = $ this ->connection ->getSupplementalDriver ()->getForeignKeys ($ table );
248+
249+ $ fksColumnsCounts = [];
250+ foreach ($ foreignKeys as $ foreignKey ) {
251+ $ tmp = &$ fksColumnsCounts [$ foreignKey ['name ' ]];
252+ $ tmp ++;
253+ }
254+ usort ($ foreignKeys , function ($ a , $ b ) use ($ fksColumnsCounts ): int {
255+ return $ fksColumnsCounts [$ b ['name ' ]] <=> $ fksColumnsCounts [$ a ['name ' ]];
256+ });
257+
258+ foreach ($ foreignKeys as $ row ) {
247259 $ structure ['belongsTo ' ][$ lowerTable ][$ row ['local ' ]] = $ row ['table ' ];
248260 $ structure ['hasMany ' ][strtolower ($ row ['table ' ])][$ table ][] = $ row ['local ' ];
249261 }
You can’t perform that action at this time.
0 commit comments