Skip to content

Commit

Permalink
Additional fix for #4167
Browse files Browse the repository at this point in the history
  • Loading branch information
samdark committed Feb 3, 2018
1 parent 2ebe9b6 commit 9e5e427
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion framework/gii/generators/model/ModelCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,8 @@ protected function generateRelations()
protected function isRelationTable($table)
{
$pk=$table->primaryKey;
return (count($pk) === 2 // we want 2 columns
$count=is_array($pk) ? count($pk) : 1;
return ($count === 2 // we want 2 columns
&& isset($table->foreignKeys[$pk[0]]) // pk column 1 is also a foreign key
&& isset($table->foreignKeys[$pk[1]]) // pk column 2 is also a foriegn key
&& $table->foreignKeys[$pk[0]][0] !== $table->foreignKeys[$pk[1]][0]); // and the foreign keys point different tables
Expand Down

0 comments on commit 9e5e427

Please sign in to comment.