Final Class Yiisoft\ActiveRecord\Internal\TableNameAndAliasResolver
| Inheritance | Yiisoft\ |
|---|
Public Methods
| Method | Description | Defined By |
|---|---|---|
| resolve() | Returns the table name and the table alias. | Yiisoft\ |
Method Details
Returns the table name and the table alias.
| public static array resolve ( Yiisoft\ | ||
| $query | Yiisoft\ |
|
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];
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.