@@ -138,8 +138,9 @@ public function isJunctionTable(Table $table, $ignoreReferencedTables = false)
138138 return false ;
139139 }
140140
141- if ($ table ->hasPrimaryKey ()) {
142- $ pkColumns = $ table ->getPrimaryKey ()->getUnquotedColumns ();
141+ $ primaryKey = $ table ->getPrimaryKey ();
142+ if ($ primaryKey ) {
143+ $ pkColumns = $ primaryKey ->getUnquotedColumns ();
143144 } else {
144145 $ pkColumns = [];
145146 }
@@ -154,7 +155,7 @@ public function isJunctionTable(Table $table, $ignoreReferencedTables = false)
154155
155156 $ fkColumnNames = [];
156157 foreach ($ foreignKeys as $ foreignKey ) {
157- $ fkColumns = $ foreignKey ->getColumns ();
158+ $ fkColumns = $ foreignKey ->getLocalColumns ();
158159 if (count ($ fkColumns ) !== 1 ) {
159160 return false ;
160161 }
@@ -309,15 +310,15 @@ private function buildSchemaGraph()
309310 foreach ($ fks as $ fk ) {
310311 // Create an undirected edge, with weight = 1
311312 $ 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 )) {
315316 $ cost = self ::$ WEIGHT_INHERITANCE_FK ;
316317 } else {
317318 $ cost = self ::$ WEIGHT_FK ;
318319 }
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 ()];
321322 }
322323
323324 $ edge ->setWeight ($ cost );
@@ -503,18 +504,15 @@ public function setForeignKeyCosts(array $fkCosts)
503504 /**
504505 * Returns true if this foreign key represents an inheritance relationship,
505506 * i.e. if this foreign key is based on a primary key.
506- *
507- * @param ForeignKeyConstraint $fk
508- *
509- * @return true
510507 */
511- private function isInheritanceRelationship (ForeignKeyConstraint $ fk )
508+ private function isInheritanceRelationship (Table $ localTable , ForeignKeyConstraint $ fk ): bool
512509 {
513- if (!$ fk ->getLocalTable ()->hasPrimaryKey ()) {
510+ $ primaryKey = $ localTable ->getPrimaryKey ();
511+ if ($ primaryKey === null ) {
514512 return false ;
515513 }
516514 $ fkColumnNames = $ fk ->getUnquotedLocalColumns ();
517- $ pkColumnNames = $ fk -> getLocalTable ()-> getPrimaryKey () ->getUnquotedColumns ();
515+ $ pkColumnNames = $ primaryKey ->getUnquotedColumns ();
518516
519517 sort ($ fkColumnNames );
520518 sort ($ pkColumnNames );
@@ -551,12 +549,12 @@ private function getParentRelationshipWithoutCache($tableName)
551549 {
552550 $ table = $ this ->getSchema ()->getTable ($ tableName );
553551 foreach ($ table ->getForeignKeys () as $ fk ) {
554- if ($ this ->isInheritanceRelationship ($ fk )) {
552+ if ($ this ->isInheritanceRelationship ($ table , $ fk )) {
555553 return $ fk ;
556554 }
557555 }
558556
559- return ;
557+ return null ;
560558 }
561559
562560 /**
@@ -594,7 +592,7 @@ private function getChildrenRelationshipsWithoutCache($tableName)
594592 }
595593 $ fks = $ this ->removeDuplicates ($ table ->getForeignKeys ());
596594 foreach ($ fks as $ fk ) {
597- if ($ fk ->getForeignTableName () === $ tableName && $ this ->isInheritanceRelationship ($ fk )) {
595+ if ($ fk ->getForeignTableName () === $ tableName && $ this ->isInheritanceRelationship ($ table , $ fk )) {
598596 $ children [] = $ fk ;
599597 }
600598 }
0 commit comments