@@ -302,7 +302,8 @@ private function buildSchemaGraph()
302
302
303
303
// Then, let's create all the edges
304
304
foreach ($ this ->getSchema ()->getTables () as $ table ) {
305
- foreach ($ table ->getForeignKeys () as $ fk ) {
305
+ $ fks = $ this ->removeDuplicates ($ table ->getForeignKeys ());
306
+ foreach ($ fks as $ fk ) {
306
307
// Create an undirected edge, with weight = 1
307
308
$ edge = $ graph ->getVertex ($ table ->getName ())->createEdge ($ graph ->getVertex ($ fk ->getForeignTableName ()));
308
309
if (isset ($ this ->alteredCosts [$ fk ->getLocalTable ()->getName ()][implode (', ' , $ fk ->getLocalColumns ())])) {
@@ -340,6 +341,22 @@ private function buildSchemaGraph()
340
341
return $ graph ;
341
342
}
342
343
344
+ /**
345
+ * Remove duplicate foreign keys (assumes that all foreign yes are from the same local table).
346
+ *
347
+ * @param ForeignKeyConstraint[] $foreignKeys
348
+ * @return ForeignKeyConstraint[]
349
+ */
350
+ private function removeDuplicates (array $ foreignKeys )
351
+ {
352
+ $ fks = [];
353
+ foreach ($ foreignKeys as $ foreignKey ) {
354
+ $ fks [implode ('__`__ ' , $ foreignKey ->getLocalColumns ())] = $ foreignKey ;
355
+ }
356
+
357
+ return array_values ($ fks );
358
+ }
359
+
343
360
/**
344
361
* Returns the schema (from the schema manager or the cache if needed).
345
362
*
@@ -572,7 +589,8 @@ private function getChildrenRelationshipsWithoutCache($tableName)
572
589
if ($ table ->getName () === $ tableName ) {
573
590
continue ;
574
591
}
575
- foreach ($ table ->getForeignKeys () as $ fk ) {
592
+ $ fks = $ this ->removeDuplicates ($ table ->getForeignKeys ());
593
+ foreach ($ fks as $ fk ) {
576
594
if ($ fk ->getForeignTableName () === $ tableName && $ this ->isInheritanceRelationship ($ fk )) {
577
595
$ children [] = $ fk ;
578
596
}
0 commit comments