diff --git a/Database/ActiveQuery.php b/Database/ActiveQuery.php index 747500b4..f415d656 100644 --- a/Database/ActiveQuery.php +++ b/Database/ActiveQuery.php @@ -43,8 +43,6 @@ class ActiveQuery extends Component implements ISqlBuilder public array $attributes = []; - private SqlBuilder $builder; - /** * Comply constructor. diff --git a/Database/Query.php b/Database/Query.php index d1b74f78..dcef535c 100644 --- a/Database/Query.php +++ b/Database/Query.php @@ -22,13 +22,22 @@ class Query implements ISqlBuilder use QueryTrait; + + /** + * @throws Exception + */ + public function __construct() + { + $this->builder = SqlBuilder::builder($this); + } + /** * @return string * @throws Exception */ public function getSql(): string { - return SqlBuilder::builder($this)->get(); + return $this->builder->get(); } @@ -38,7 +47,7 @@ class Query implements ISqlBuilder */ public function getCondition(): string { - return SqlBuilder::builder($this)->getCondition(); + return $this->builder->getCondition(); } diff --git a/Database/Traits/QueryTrait.php b/Database/Traits/QueryTrait.php index efa1a7ca..b6988958 100644 --- a/Database/Traits/QueryTrait.php +++ b/Database/Traits/QueryTrait.php @@ -40,6 +40,9 @@ trait QueryTrait public bool $ifNotWhere = false; + + private SqlBuilder $builder; + /** * @var ActiveRecord|string|null */