Commit 38476309 by Stephen Seliuk Committed by Alexander Makarov

Fixes #4971: Fixed hardcoded table names in `viaTable` expression in model generator

parent 00e4d63e
......@@ -9,6 +9,7 @@ Yii Framework 2 gii extension Change Log
- Bug #3265: Fixed incorrect controller class name validation (suralc)
- Bug #3693: Fixed broken Gii preview when a file is unchanged (cebe)
- Bug #4410: Fixed Gii to preserve database column order in generated _form.php (kmindi)
- Bug #4971: Fixed hardcoded table names in `viaTable` expression in model generator (stepanselyuk)
- Enh #2018: Search model is not required anymore in CRUD generator (johonunu)
- Enh #3088: The gii module will manage their own URL rules now (qiangxue)
- Enh #3222: Added `useTablePrefix` option to the model generator for Gii (horizons2)
......
......@@ -354,7 +354,7 @@ class Generator extends \yii\gii\Generator
$viaLink = $this->generateRelationLink([$table->primaryKey[0] => $fks[$table->primaryKey[0]][1]]);
$relationName = $this->generateRelationName($relations, $className0, $db->getTableSchema($table0), $table->primaryKey[1], true);
$relations[$className0][$relationName] = [
"return \$this->hasMany($className1::className(), $link)->viaTable('{$table->name}', $viaLink);",
"return \$this->hasMany($className1::className(), $link)->viaTable('{" . $this->generateTableName($table->name) . "}', $viaLink);",
$className1,
true,
];
......@@ -363,7 +363,7 @@ class Generator extends \yii\gii\Generator
$viaLink = $this->generateRelationLink([$table->primaryKey[1] => $fks[$table->primaryKey[1]][1]]);
$relationName = $this->generateRelationName($relations, $className1, $db->getTableSchema($table1), $table->primaryKey[0], true);
$relations[$className1][$relationName] = [
"return \$this->hasMany($className0::className(), $link)->viaTable('{$table->name}', $viaLink);",
"return \$this->hasMany($className0::className(), $link)->viaTable('{" . $this->generateTableName($table->name) . "}', $viaLink);",
$className0,
true,
];
......
......@@ -20,7 +20,7 @@ namespace <?= $generator->ns ?>;
use Yii;
/**
* This is the model class for table "<?= $tableName ?>".
* This is the model class for table "<?= $generator->generateTableName($tableName) ?>".
*
<?php foreach ($tableSchema->columns as $column): ?>
* @property <?= "{$column->phpType} \${$column->name}\n" ?>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment