diff --git a/Traits/QueryTrait.php b/Traits/QueryTrait.php index 0f8bcf8..08b9bdc 100644 --- a/Traits/QueryTrait.php +++ b/Traits/QueryTrait.php @@ -434,13 +434,15 @@ abstract class QueryTrait extends Component implements ActiveQueryInterface, ISq /** - * @param string|Closure $tableName + * @param string|Closure|Query $tableName * * @return $this */ - public function from(string|Closure $tableName): static + public function from(string|Closure|Query $tableName): static { - if ($tableName instanceof Closure) { + if ($tableName instanceof Query) { + $this->from = '(' . $tableName->build() . ')'; + } else if ($tableName instanceof Closure) { $this->from = '(' . $this->makeClosureFunction($tableName) . ')'; } else if (class_exists($tableName)) { $this->from = (new $tableName)->getTable();