0 follower

Final Class Yiisoft\ActiveRecord\Internal\TableNameAndAliasResolver

InheritanceYiisoft\ActiveRecord\Internal\TableNameAndAliasResolver

Public Methods

Hide inherited methods

Method Description Defined By
resolve() Returns the table name and the table alias. Yiisoft\ActiveRecord\Internal\TableNameAndAliasResolver

Method Details

Hide inherited methods

resolve() public static method

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];
}