This commit is contained in:
2021-03-18 18:15:28 +08:00
parent 788d5a524b
commit 755aa7e2e5
2 changed files with 11 additions and 2 deletions
+10 -1
View File
@@ -254,7 +254,16 @@ class SqlBuilder extends Component
*/
public function tableName(): string
{
return $this->query->modelClass::getTable();
if ($this->query->from instanceof \Closure) {
$this->query->from = call_user_func($this->query->from, new ActiveQuery($this->query->modelClass));
}
if ($this->query->from instanceof ActiveQuery) {
$this->query->from = '(' . SqlBuilder::builder($this->query->from)->get($this->query->from) . ')';
}
if (empty($this->query->from)) {
return $this->query->modelClass::getTable();
}
return $this->query->from;
}
}
+1 -1
View File
@@ -28,7 +28,7 @@ trait QueryTrait
public ?int $offset = NULL;
public ?int $limit = NULL;
public string $group = '';
public string $from = '';
public string|\Closure|ActiveQuery $from = '';
public string $alias = 't1';
public array $filter = [];