Final Class Yiisoft\ActiveRecord\Internal\TableNameAndAliasResolver
| Inheritance | Yiisoft\ActiveRecord\Internal\TableNameAndAliasResolver |
|---|
Public Methods
| Method | Description | Defined By |
|---|---|---|
| resolve() | Returns the table name and the table alias. | Yiisoft\ActiveRecord\Internal\TableNameAndAliasResolver |
Method Details
Returns the table name and the table alias.
| public static array resolve ( Yiisoft\ActiveRecord\ActiveQueryInterface $query ) | ||
| $query | Yiisoft\ActiveRecord\ActiveQueryInterface | |
public static function resolve(ActiveQueryInterface $query): array
{
$from = $query->getFrom();
if (empty($from)) {
$tableName = $query->getModel()->tableName();
} else {
$alias = array_key_first($from);
$tableName = $from[$alias];
if (is_string($alias)) {
return [$tableName, $alias];
}
if ($tableName instanceof ExpressionInterface) {
throw new LogicException('Alias must be set for a table specified by an expression.');
}
}
$alias = preg_match('/^(.*?)\s+({{\w+}}|\w+)$/', $tableName, $matches)
? $matches[2]
: $tableName;
return [$tableName, $alias];
}
Signup or Login in order to comment.