@@ -138,8 +138,9 @@ public function isJunctionTable(Table $table, $ignoreReferencedTables = false)
138
138
return false ;
139
139
}
140
140
141
- if ($ table ->hasPrimaryKey ()) {
142
- $ pkColumns = $ table ->getPrimaryKey ()->getUnquotedColumns ();
141
+ $ primaryKey = $ table ->getPrimaryKey ();
142
+ if ($ primaryKey ) {
143
+ $ pkColumns = $ primaryKey ->getUnquotedColumns ();
143
144
} else {
144
145
$ pkColumns = [];
145
146
}
@@ -154,7 +155,7 @@ public function isJunctionTable(Table $table, $ignoreReferencedTables = false)
154
155
155
156
$ fkColumnNames = [];
156
157
foreach ($ foreignKeys as $ foreignKey ) {
157
- $ fkColumns = $ foreignKey ->getColumns ();
158
+ $ fkColumns = $ foreignKey ->getLocalColumns ();
158
159
if (count ($ fkColumns ) !== 1 ) {
159
160
return false ;
160
161
}
@@ -309,15 +310,15 @@ private function buildSchemaGraph()
309
310
foreach ($ fks as $ fk ) {
310
311
// Create an undirected edge, with weight = 1
311
312
$ edge = $ graph ->getVertex ($ table ->getName ())->createEdge ($ graph ->getVertex ($ fk ->getForeignTableName ()));
312
- if (isset ($ this ->alteredCosts [$ fk -> getLocalTable () ->getName ()][implode (', ' , $ fk ->getLocalColumns ())])) {
313
- $ cost = $ this ->alteredCosts [$ fk -> getLocalTable () ->getName ()][implode (', ' , $ fk ->getLocalColumns ())];
314
- } elseif ($ this ->isInheritanceRelationship ($ fk )) {
313
+ if (isset ($ this ->alteredCosts [$ table ->getName ()][implode (', ' , $ fk ->getLocalColumns ())])) {
314
+ $ cost = $ this ->alteredCosts [$ table ->getName ()][implode (', ' , $ fk ->getLocalColumns ())];
315
+ } elseif ($ this ->isInheritanceRelationship ($ table , $ fk )) {
315
316
$ cost = self ::$ WEIGHT_INHERITANCE_FK ;
316
317
} else {
317
318
$ cost = self ::$ WEIGHT_FK ;
318
319
}
319
- if (isset ($ this ->alteredTableCosts [$ fk -> getLocalTable () ->getName ()])) {
320
- $ cost *= $ this ->alteredTableCosts [$ fk -> getLocalTable () ->getName ()];
320
+ if (isset ($ this ->alteredTableCosts [$ table ->getName ()])) {
321
+ $ cost *= $ this ->alteredTableCosts [$ table ->getName ()];
321
322
}
322
323
323
324
$ edge ->setWeight ($ cost );
@@ -503,18 +504,15 @@ public function setForeignKeyCosts(array $fkCosts)
503
504
/**
504
505
* Returns true if this foreign key represents an inheritance relationship,
505
506
* i.e. if this foreign key is based on a primary key.
506
- *
507
- * @param ForeignKeyConstraint $fk
508
- *
509
- * @return true
510
507
*/
511
- private function isInheritanceRelationship (ForeignKeyConstraint $ fk )
508
+ private function isInheritanceRelationship (Table $ localTable , ForeignKeyConstraint $ fk ): bool
512
509
{
513
- if (!$ fk ->getLocalTable ()->hasPrimaryKey ()) {
510
+ $ primaryKey = $ localTable ->getPrimaryKey ();
511
+ if ($ primaryKey === null ) {
514
512
return false ;
515
513
}
516
514
$ fkColumnNames = $ fk ->getUnquotedLocalColumns ();
517
- $ pkColumnNames = $ fk -> getLocalTable ()-> getPrimaryKey () ->getUnquotedColumns ();
515
+ $ pkColumnNames = $ primaryKey ->getUnquotedColumns ();
518
516
519
517
sort ($ fkColumnNames );
520
518
sort ($ pkColumnNames );
@@ -551,12 +549,12 @@ private function getParentRelationshipWithoutCache($tableName)
551
549
{
552
550
$ table = $ this ->getSchema ()->getTable ($ tableName );
553
551
foreach ($ table ->getForeignKeys () as $ fk ) {
554
- if ($ this ->isInheritanceRelationship ($ fk )) {
552
+ if ($ this ->isInheritanceRelationship ($ table , $ fk )) {
555
553
return $ fk ;
556
554
}
557
555
}
558
556
559
- return ;
557
+ return null ;
560
558
}
561
559
562
560
/**
@@ -594,7 +592,7 @@ private function getChildrenRelationshipsWithoutCache($tableName)
594
592
}
595
593
$ fks = $ this ->removeDuplicates ($ table ->getForeignKeys ());
596
594
foreach ($ fks as $ fk ) {
597
- if ($ fk ->getForeignTableName () === $ tableName && $ this ->isInheritanceRelationship ($ fk )) {
595
+ if ($ fk ->getForeignTableName () === $ tableName && $ this ->isInheritanceRelationship ($ table , $ fk )) {
598
596
$ children [] = $ fk ;
599
597
}
600
598
}
0 commit comments