Browse Source

fixed crud to work with table that has no PK but AR defines one

tags/2.0.0-alpha
Carsten Brandt 11 years ago
parent
commit
faed08e620
  1. 12
      extensions/gii/generators/crud/Generator.php

12
extensions/gii/generators/crud/Generator.php

@ -341,7 +341,9 @@ class Generator extends \yii\gii\Generator
public function generateUrlParams() public function generateUrlParams()
{ {
$pks = $this->getTableSchema()->primaryKey; /** @var ActiveRecord $class */
$class = $this->modelClass;
$pks = $class::primaryKey();
if (count($pks) === 1) { if (count($pks) === 1) {
return "'id' => \$model->{$pks[0]}"; return "'id' => \$model->{$pks[0]}";
} else { } else {
@ -355,7 +357,9 @@ class Generator extends \yii\gii\Generator
public function generateActionParams() public function generateActionParams()
{ {
$pks = $this->getTableSchema()->primaryKey; /** @var ActiveRecord $class */
$class = $this->modelClass;
$pks = $class::primaryKey();
if (count($pks) === 1) { if (count($pks) === 1) {
return '$id'; return '$id';
} else { } else {
@ -366,7 +370,9 @@ class Generator extends \yii\gii\Generator
public function generateActionParamComments() public function generateActionParamComments()
{ {
$table = $this->getTableSchema(); $table = $this->getTableSchema();
$pks = $table->primaryKey; /** @var ActiveRecord $class */
$class = $this->modelClass;
$pks = $class::primaryKey();
if (count($pks) === 1) { if (count($pks) === 1) {
return ['@param ' . $table->columns[$pks[0]]->phpType . ' $id']; return ['@param ' . $table->columns[$pks[0]]->phpType . ' $id'];
} else { } else {

Loading…
Cancel
Save