diff --git a/Database/SqlBuilder.php b/Database/SqlBuilder.php index 702e54e9..bdbe595d 100644 --- a/Database/SqlBuilder.php +++ b/Database/SqlBuilder.php @@ -177,7 +177,7 @@ class SqlBuilder extends Component public function one(): string { $this->query->limit(0, 1); - if (empty($this->from)) { + if (empty($this->query->from) && !empty($this->query->modelClass)) { $this->query->from($this->query->getTable()); } return $this->_prefix(true); @@ -190,7 +190,7 @@ class SqlBuilder extends Component */ public function all(): string { - if (empty($this->from)) { + if (empty($this->query->from) && !empty($this->query->modelClass)) { $this->query->from($this->query->getTable()); } return $this->_prefix(true); @@ -203,7 +203,7 @@ class SqlBuilder extends Component */ public function count(): string { - if (empty($this->from)) { + if (empty($this->query->from) && !empty($this->query->modelClass)) { $this->query->from($this->query->getTable()); } return $this->_prefix();