Final Class Yiisoft\Yii\Gii\Generator\ActiveRecord\Relation
| Inheritance | Yiisoft\Yii\Gii\Generator\ActiveRecord\Relation |
|---|
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\Yii\Gii\Generator\ActiveRecord\Relation | |
| getGetterMethodName() | Returns the method name for the relation getter (e.g., "getProfile"). | Yiisoft\Yii\Gii\Generator\ActiveRecord\Relation |
| getGetterReturnType() | Returns the return type for the getter method. | Yiisoft\Yii\Gii\Generator\ActiveRecord\Relation |
| getInverseOf() | Yiisoft\Yii\Gii\Generator\ActiveRecord\Relation | |
| getLink() | Yiisoft\Yii\Gii\Generator\ActiveRecord\Relation | |
| getName() | Yiisoft\Yii\Gii\Generator\ActiveRecord\Relation | |
| getQueryMethodName() | Returns the method name for the relation query (e.g., "getProfileQuery"). | Yiisoft\Yii\Gii\Generator\ActiveRecord\Relation |
| getRelatedModel() | Yiisoft\Yii\Gii\Generator\ActiveRecord\Relation | |
| getRelationMethod() | Returns relation method name. | Yiisoft\Yii\Gii\Generator\ActiveRecord\Relation |
Method Details
| public mixed __construct ( \Yiisoft\Db\Schema\TableSchemaInterface $tableSchema, string[] $columnNames, \Yiisoft\Db\Schema\TableSchemaInterface $foreignTableSchema, string[] $foreignColumnNames ) | ||
| $tableSchema | \Yiisoft\Db\Schema\TableSchemaInterface | |
| $columnNames | string[] | |
| $foreignTableSchema | \Yiisoft\Db\Schema\TableSchemaInterface | |
| $foreignColumnNames | string[] | |
public function __construct(
private readonly TableSchemaInterface $tableSchema,
private readonly array $columnNames,
private readonly TableSchemaInterface $foreignTableSchema,
private readonly array $foreignColumnNames,
) {}
Returns the method name for the relation getter (e.g., "getProfile").
| public string getGetterMethodName ( ) |
public function getGetterMethodName(): string
{
return 'get' . ucfirst($this->getName());
}
Returns the return type for the getter method.
| public string getGetterReturnType ( ) |
public function getGetterReturnType(): string
{
if (!$this->isUniqueForeignColumns()) {
return 'array';
}
return '?' . $this->getRelatedModel();
}
| public string getInverseOf ( ) |
public function getInverseOf(): string
{
return ArHelper::getRelationName(
$this->foreignColumnNames,
$this->tableSchema->getName(),
$this->isUniqueColumns(),
);
}
| public string[] getLink ( ) |
public function getLink(): array
{
$link = [];
foreach ($this->columnNames as $index => $columnName) {
$foreignColumnName = $this->foreignColumnNames[$index];
$link[$foreignColumnName] = $columnName;
}
return $link;
}
| public string getName ( ) |
public function getName(): string
{
return $this->name ??= ArHelper::getRelationName(
$this->columnNames,
$this->foreignTableSchema->getName(),
$this->isUniqueForeignColumns(),
);
}
Returns the method name for the relation query (e.g., "getProfileQuery").
| public string getQueryMethodName ( ) |
public function getQueryMethodName(): string
{
return $this->getGetterMethodName() . 'Query';
}
| public string getRelatedModel ( ) |
public function getRelatedModel(): string
{
$foreignTableName = $this->foreignTableSchema->getName();
return (new Inflector())->tableToClass($foreignTableName);
}
Returns relation method name.
| public string getRelationMethod ( ) |
public function getRelationMethod(): string
{
return $this->isUniqueForeignColumns() ? 'hasOne' : 'hasMany';
}
Signup or Login in order to comment.