Commit aaa4e429 by Qiang Xue

Fixes #2687: table alias may not be respected when specified in relation query.

parent 5bbceebc
...@@ -453,7 +453,14 @@ class ActiveQuery extends Query implements ActiveQueryInterface ...@@ -453,7 +453,14 @@ class ActiveQuery extends Query implements ActiveQueryInterface
$modelClass = $query->modelClass; $modelClass = $query->modelClass;
$tableName = $modelClass::tableName(); $tableName = $modelClass::tableName();
} else { } else {
$tableName = reset($query->from); $tableName = '';
foreach ($query->from as $alias => $tableName) {
if (is_string($alias)) {
return [$tableName, $alias];
} else {
break;
}
}
} }
if (preg_match('/^(.*?)\s+({{\w+}}|\w+)$/', $tableName, $matches)) { if (preg_match('/^(.*?)\s+({{\w+}}|\w+)$/', $tableName, $matches)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment