This commit is contained in:
2021-08-02 16:38:50 +08:00
parent fd7415b7f1
commit a095c94e21
15 changed files with 1593 additions and 1513 deletions
+4 -19
View File
@@ -12,7 +12,6 @@ namespace Database;
use Database\Traits\QueryTrait;
use Exception;
use Snowflake\Abstracts\Component;
use Snowflake\Snowflake;
/**
* Class ActiveQuery
@@ -107,22 +106,12 @@ class ActiveQuery extends Component implements ISqlBuilder
if (is_string($name)) {
$name = explode(',', $name);
}
foreach ($name as $key => $val) {
foreach ($name as $val) {
array_push($this->with, $val);
}
return $this;
}
/**
* @param bool $isArray
* @return $this
*/
public function asArray(bool $isArray = TRUE): static
{
$this->asArray = $isArray;
return $this;
}
/**
* @param $sql
@@ -137,20 +126,16 @@ class ActiveQuery extends Component implements ISqlBuilder
/**
* @return ActiveRecord|array|null
* @return ActiveRecord|null
* @throws Exception
*/
public function first(): ActiveRecord|array|null
public function first(): ActiveRecord|null
{
$data = $this->execute($this->builder->one())->one();
if (empty($data)) {
return NULL;
}
$newModel = $this->modelClass::populate($data);
if ($this->asArray) {
return $newModel->toArray();
}
return $newModel;
return $this->modelClass::populate($data);
}