Final Class Yiisoft\Yii\Gii\Generator\ActiveRecord\Relation
| Inheritance | Yiisoft\ |
|---|
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\ |
|
| getGetterMethodName() | Returns the method name for the relation getter (e.g., "getProfile"). | Yiisoft\ |
| getGetterReturnType() | Returns the return type for the getter method. | Yiisoft\ |
| getInverseOf() | Yiisoft\ |
|
| getLink() | Yiisoft\ |
|
| getName() | Yiisoft\ |
|
| getQueryMethodName() | Returns the method name for the relation query (e.g., "getProfileQuery"). | Yiisoft\ |
| getRelatedModel() | Yiisoft\ |
|
| getRelationMethod() | Returns relation method name. | Yiisoft\ |
Method Details
| public mixed __construct ( \ | ||
| $tableSchema | \ |
|
| $columnNames | string[] | |
| $foreignTableSchema | \ |
|
| $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';
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.