Skip to content

Commit

Permalink
Apply @vjik review
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov committed Aug 6, 2023
1 parent ef73c6b commit b6d16fe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,21 +220,22 @@ protected function loadTableForeignKeys(string $tableName): array
$primaryKey = $this->getTablePrimaryKey($table);

if ($primaryKey !== null) {
/** @psalm-var string $primaryKeyName */
foreach ((array) $primaryKey->getColumnNames() as $i => $primaryKeyName) {
$foreignKey[$i]['to'] = $primaryKeyName;
/** @psalm-var string $primaryKeyColumnName */
foreach ((array) $primaryKey->getColumnNames() as $i => $primaryKeyColumnName) {
$foreignKey[$i]['to'] = $primaryKeyColumnName;
}
}
}

$fk = (new ForeignKeyConstraint())
->name($id)
->columnNames(array_column($foreignKey, 'from'))
->foreignTableName($table)
->foreignColumnNames(array_column($foreignKey, 'to'))
->onDelete($foreignKey[0]['on_delete'])
->onUpdate($foreignKey[0]['on_update']);

$result[(int) $id] = $fk;
$result[] = $fk;
}
}

Expand Down Expand Up @@ -400,14 +401,15 @@ protected function findConstraints(TableSchemaInterface $table): void
/** @psalm-var ForeignKeyConstraint[] $foreignKeysList */
$foreignKeysList = $this->getTableForeignKeys($table->getName(), true);

foreach ($foreignKeysList as $id => $foreignKey) {
foreach ($foreignKeysList as $foreignKey) {
/** @var array<string> $columnNames */
$columnNames = (array) $foreignKey->getColumnNames();
$columnNames = array_combine($columnNames, $foreignKey->getForeignColumnNames());

$foreignReference = array_merge([$foreignKey->getForeignTableName()], $columnNames);

$table->foreignKey($id, $foreignReference);
/** @psalm-suppress InvalidCast */
$table->foreignKey((int) $foreignKey->getName(), $foreignReference);
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/TableSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
*/
final class TableSchema extends AbstractTableSchema
{
/**
* @deprecated will be removed in version 2.0.0
*/
public function compositeForeignKey(int $id, string $from, string $to): void
{
$this->foreignKeys[$id][$from] = $to;
Expand Down

0 comments on commit b6d16fe

Please sign in to comment.