Browse Source

Fixes #1063

tags/2.0.0-beta
Gudz Taras 11 years ago committed by gudz.taras@gmail.com
parent
commit
5b1ba04a9d
  1. 16
      framework/yii/gii/generators/model/Generator.php

16
framework/yii/gii/generators/model/Generator.php

@ -265,8 +265,8 @@ class Generator extends \yii\gii\Generator
$link = $this->generateRelationLink(array_flip($refs)); $link = $this->generateRelationLink(array_flip($refs));
$relationName = $this->generateRelationName($relations, $className, $table, $fks[0], false); $relationName = $this->generateRelationName($relations, $className, $table, $fks[0], false);
$relations[$className][$relationName] = [ $relations[$className][$relationName] = [
"return \$this->hasOne('$this->ns\\$refClassName', $link);", "return \$this->hasOne($refClassName::className(), $link);",
$this->ns . '\\' . $refClassName, $refClassName,
false, false,
]; ];
@ -281,8 +281,8 @@ class Generator extends \yii\gii\Generator
$link = $this->generateRelationLink($refs); $link = $this->generateRelationLink($refs);
$relationName = $this->generateRelationName($relations, $refClassName, $refTable, $className, $hasMany); $relationName = $this->generateRelationName($relations, $refClassName, $refTable, $className, $hasMany);
$relations[$refClassName][$relationName] = [ $relations[$refClassName][$relationName] = [
"return \$this->" . ($hasMany ? 'hasMany' : 'hasOne') . "('$this->ns\\$className', $link);", "return \$this->" . ($hasMany ? 'hasMany' : 'hasOne') . "($refClassName::className(), $link);",
$this->ns . '\\' . $className, $className,
$hasMany, $hasMany,
]; ];
} }
@ -299,8 +299,8 @@ class Generator extends \yii\gii\Generator
$viaLink = $this->generateRelationLink([$table->primaryKey[0] => $fks[$table->primaryKey[0]][1]]); $viaLink = $this->generateRelationLink([$table->primaryKey[0] => $fks[$table->primaryKey[0]][1]]);
$relationName = $this->generateRelationName($relations, $className0, $db->getTableSchema($table0), $table->primaryKey[1], true); $relationName = $this->generateRelationName($relations, $className0, $db->getTableSchema($table0), $table->primaryKey[1], true);
$relations[$className0][$relationName] = [ $relations[$className0][$relationName] = [
"return \$this->hasMany('$this->ns\\$className1', $link)->viaTable('{$table->name}', $viaLink);", "return \$this->hasMany($className1::className(), $link)->viaTable('{$table->name}', $viaLink);",
$this->ns . '\\' . $className0, $className0,
true, true,
]; ];
@ -308,8 +308,8 @@ class Generator extends \yii\gii\Generator
$viaLink = $this->generateRelationLink([$table->primaryKey[1] => $fks[$table->primaryKey[1]][1]]); $viaLink = $this->generateRelationLink([$table->primaryKey[1] => $fks[$table->primaryKey[1]][1]]);
$relationName = $this->generateRelationName($relations, $className1, $db->getTableSchema($table1), $table->primaryKey[0], true); $relationName = $this->generateRelationName($relations, $className1, $db->getTableSchema($table1), $table->primaryKey[0], true);
$relations[$className1][$relationName] = [ $relations[$className1][$relationName] = [
"return \$this->hasMany('$this->ns\\$className0', $link)->viaTable('{$table->name}', $viaLink);", "return \$this->hasMany($className0::className(), $link)->viaTable('{$table->name}', $viaLink);",
$this->ns . '\\' . $className1, $className1,
true, true,
]; ];
} }

Loading…
Cancel
Save