This commit is contained in:
2023-10-24 15:14:46 +08:00
parent 67c7dd8421
commit b0e627c4fb
+15 -19
View File
@@ -39,8 +39,8 @@ class ActiveQuery extends Component implements ISqlBuilder
* @var array * @var array
* 参数绑定 * 参数绑定
*/ */
public array $attributes = []; public array $attributes = [];
protected mixed $_mock = null; protected mixed $_mock = null;
/** /**
@@ -62,7 +62,7 @@ class ActiveQuery extends Component implements ISqlBuilder
*/ */
public function clear(): void public function clear(): void
{ {
$this->db = NULL; $this->db = NULL;
$this->useCache = FALSE; $this->useCache = FALSE;
} }
@@ -179,19 +179,17 @@ class ActiveQuery extends Component implements ISqlBuilder
/** /**
* @return array|Collection * @return Collection
* @throws Exception * @throws Exception
*/ */
public function get(): Collection|array public function get(): Collection
{ {
$data = $this->execute($this->builder->all(), $this->attributes)->all(); $data = $this->execute($this->builder->all(), $this->attributes)->all();
if ($data === false) { if ($data !== false) {
return new Collection($this, $data, $this->modelClass);
} else {
return new Collection($this, [], $this->modelClass); return new Collection($this, [], $this->modelClass);
} }
$collect = new Collection($this, $data, $this->modelClass);
return $this->asArray ? $collect->toArray() : $collect;
} }
@@ -261,11 +259,8 @@ class ActiveQuery extends Component implements ISqlBuilder
public function populate($data): ModelInterface|array public function populate($data): ModelInterface|array
{ {
$model = $this->modelClass->populates($data); $model = $this->modelClass->populates($data);
if ($this->asArray) {
return $model->toArray(); return $this->asArray ? $model->toArray() : $model;
} else {
return $model;
}
} }
@@ -290,10 +285,11 @@ class ActiveQuery extends Component implements ISqlBuilder
return true; return true;
} }
$generate = $this->builder->update($data); $generate = $this->builder->update($data);
if (is_bool($generate)) { if (!is_bool($generate)) {
return (bool)$this->execute($generate, $this->attributes)->exec();
} else {
return $generate; return $generate;
} }
return (bool)$this->execute($generate, $this->attributes)->exec();
} }
/** /**
@@ -305,7 +301,6 @@ class ActiveQuery extends Component implements ISqlBuilder
{ {
[$sql, $params] = $this->builder->insert($data, TRUE); [$sql, $params] = $this->builder->insert($data, TRUE);
return (bool)$this->execute($sql, $params)->exec(); return (bool)$this->execute($sql, $params)->exec();
} }
@@ -340,7 +335,8 @@ class ActiveQuery extends Component implements ISqlBuilder
$sql = $this->builder->delete(); $sql = $this->builder->delete();
if ($getSql === FALSE) { if ($getSql === FALSE) {
return (bool)$this->execute($sql, $this->attributes)->delete(); return (bool)$this->execute($sql, $this->attributes)->delete();
} else {
return $sql;
} }
return $sql;
} }
} }