Skip to content

Commit

Permalink
Fixes issue yiisoft#1063: Fatal Error while getting value from Active…
Browse files Browse the repository at this point in the history
…Relation generated by Gii
  • Loading branch information
tarasio authored and [email protected] committed Oct 24, 2013
1 parent c5801dc commit 9c5ba23
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions framework/yii/gii/generators/model/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ protected function generateRelations()
$link = $this->generateRelationLink(array_flip($refs));
$relationName = $this->generateRelationName($relations, $className, $table, $fks[0], false);
$relations[$className][$relationName] = [
"return \$this->hasOne('$refClassName', $link);",
$refClassName,
"return \$this->hasOne('$this->ns\\$refClassName', $link);",
$this->ns . '\\' . $refClassName,
false,
];

Expand All @@ -281,8 +281,8 @@ protected function generateRelations()
$link = $this->generateRelationLink($refs);
$relationName = $this->generateRelationName($relations, $refClassName, $refTable, $className, $hasMany);
$relations[$refClassName][$relationName] = [
"return \$this->" . ($hasMany ? 'hasMany' : 'hasOne') . "('$className', $link);",
$className,
"return \$this->" . ($hasMany ? 'hasMany' : 'hasOne') . "('$this->ns\\$className', $link);",
$this->ns . '\\' . $className,
$hasMany,
];
}
Expand All @@ -299,17 +299,17 @@ protected function generateRelations()
$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', $link)->viaTable('{$table->name}', $viaLink);",
$className0,
"return \$this->hasMany('$this->ns\\$className1', $link)->viaTable('{$table->name}', $viaLink);",
$this->ns . '\\' . $className0,
true,
];

$link = $this->generateRelationLink([$fks[$table->primaryKey[0]][1] => $table->primaryKey[0]]);
$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', $link)->viaTable('{$table->name}', $viaLink);",
$className1,
"return \$this->hasMany('$this->ns\\$className0', $link)->viaTable('{$table->name}', $viaLink);",
$this->ns . '\\' . $className1,
true,
];
}
Expand Down

0 comments on commit 9c5ba23

Please sign in to comment.