From d5f2e75a8ba23e67904a72c589c86f61c827796e Mon Sep 17 00:00:00 2001 From: Tom Muylle Date: Mon, 6 Mar 2017 15:37:06 +0100 Subject: [PATCH] Returns all foreign key fields and references, and only uses the first element when actually generating the migration file. This allow for more flexibility. See https://github.com/Xethron/migrations-generator/issues/125 --- .../MigrationsGenerator/Generators/ForeignKeyGenerator.php | 4 ++-- .../MigrationsGenerator/Syntax/AddForeignKeysToTable.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Xethron/MigrationsGenerator/Generators/ForeignKeyGenerator.php b/src/Xethron/MigrationsGenerator/Generators/ForeignKeyGenerator.php index 2237956..1a89029 100644 --- a/src/Xethron/MigrationsGenerator/Generators/ForeignKeyGenerator.php +++ b/src/Xethron/MigrationsGenerator/Generators/ForeignKeyGenerator.php @@ -28,8 +28,8 @@ public function generate($table, $schema, $ignoreForeignKeyNames) foreach ( $foreignKeys as $foreignKey ) { $fields[] = [ 'name' => $this->getName($foreignKey, $ignoreForeignKeyNames), - 'field' => $foreignKey->getLocalColumns()[0], - 'references' => $foreignKey->getForeignColumns()[0], + 'field' => $foreignKey->getLocalColumns(), + 'references' => $foreignKey->getForeignColumns(), 'on' => $foreignKey->getForeignTableName(), 'onUpdate' => $foreignKey->hasOption('onUpdate') ? $foreignKey->getOption('onUpdate') : 'RESTRICT', 'onDelete' => $foreignKey->hasOption('onDelete') ? $foreignKey->getOption('onDelete') : 'RESTRICT', diff --git a/src/Xethron/MigrationsGenerator/Syntax/AddForeignKeysToTable.php b/src/Xethron/MigrationsGenerator/Syntax/AddForeignKeysToTable.php index 69475a9..75e7624 100644 --- a/src/Xethron/MigrationsGenerator/Syntax/AddForeignKeysToTable.php +++ b/src/Xethron/MigrationsGenerator/Syntax/AddForeignKeysToTable.php @@ -14,14 +14,14 @@ class AddForeignKeysToTable extends Table { */ protected function getItem(array $foreignKey) { - $value = $foreignKey['field']; + $value = $foreignKey['field'][0]; if ( ! empty($foreignKey['name'])) { $value .= "', '". $foreignKey['name']; } $output = sprintf( "\$table->foreign('%s')->references('%s')->on('%s')", $value, - $foreignKey['references'], + $foreignKey['references'][0], $foreignKey['on'] ); if ($foreignKey['onUpdate']) {