Final Class Yiisoft\Yii\Gii\Generator\ActiveRecord\InverseRelation
| Inheritance | Yiisoft\Yii\Gii\Generator\ActiveRecord\InverseRelation » Yiisoft\Yii\Gii\Generator\ActiveRecord\AbstractRelation |
|---|
Represents an inverse relation (incoming foreign key from another table).
For example, if a Post table has a FK to User, then User has an inverse hasMany relation to Post.
Public Methods
Method Details
| public mixed __construct ( \Yiisoft\Db\Constraint\ForeignKey $foreignKey, string $relatedTableName ) | ||
| $foreignKey | \Yiisoft\Db\Constraint\ForeignKey | |
| $relatedTableName | string | |
public function __construct(
private readonly ForeignKey $foreignKey,
private readonly string $relatedTableName,
) {}
Defined in: Yiisoft\Yii\Gii\Generator\ActiveRecord\AbstractRelation::getGetterMethodName()
Returns the method name for the relation getter (e.g., "getProfile").
| public string getGetterMethodName ( ) |
public function getGetterMethodName(): string
{
return 'get' . $this->getRelatedModel();
}
Defined in: Yiisoft\Yii\Gii\Generator\ActiveRecord\AbstractRelation::getGetterReturnType()
Returns the return type for the getter method.
| public string getGetterReturnType ( ) |
public function getGetterReturnType(): string
{
if ($this->isHasMany()) {
return 'array';
}
return '?' . $this->getRelatedModel();
}
| public string getInverseOf ( ) |
public function getInverseOf(): string
{
return lcfirst((new Inflector())->tableToClass($this->foreignKey->foreignTableName));
}
| public array getLink ( ) |
public function getLink(): array
{
$link = [];
foreach ($this->foreignKey->columnNames as $index => $columnName) {
$link[$columnName] = $this->foreignKey->foreignColumnNames[$index];
}
return $link;
}
| public string getName ( ) |
public function getName(): string
{
return lcfirst($this->getRelatedModel());
}
Defined in: Yiisoft\Yii\Gii\Generator\ActiveRecord\AbstractRelation::getQueryMethodName()
Returns the method name for the relation query (e.g., "getProfileQuery").
| public string getQueryMethodName ( ) |
public function getQueryMethodName(): string
{
return 'get' . $this->getRelatedModel() . 'Query';
}
| public string getRelatedModel ( ) |
public function getRelatedModel(): string
{
return (new Inflector())->tableToClass($this->relatedTableName);
}
Defined in: Yiisoft\Yii\Gii\Generator\ActiveRecord\AbstractRelation::isHasMany()
Returns true if this is a hasMany relation.
| public boolean isHasMany ( ) |
public function isHasMany(): bool
{
return false;
}
Defined in: Yiisoft\Yii\Gii\Generator\ActiveRecord\AbstractRelation::isHasOne()
Returns true if this is a hasOne relation.
| public boolean isHasOne ( ) |
public function isHasOne(): bool
{
return true;
}
Signup or Login in order to comment.