From 9b1489f576fc59b3beaaf1082bb59f9dae593584 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Sat, 1 Apr 2023 15:54:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ActiveQuery.php | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/ActiveQuery.php b/ActiveQuery.php index a65a37a..1ca736e 100644 --- a/ActiveQuery.php +++ b/ActiveQuery.php @@ -160,10 +160,11 @@ class ActiveQuery extends Component implements ISqlBuilder public function first(): ModelInterface|null { $data = $this->execute($this->builder->one())->one(); - if (empty($data)) { - return NULL; + if (!is_null($data)) { + return $this->populate($data); + } else { + return NULL; } - return $this->populate($data); } @@ -234,9 +235,8 @@ class ActiveQuery extends Component implements ISqlBuilder if (!($data = $this->execute($this->builder->all())->all())) { return new Collection($this, [], $this->modelClass); } - if (!empty($this->with)) { - $this->getWith($this->modelClass); - } + + $this->getWith($this->modelClass); $collect = new Collection($this, $data, $this->modelClass); if ($this->asArray) { return $collect->toArray(); @@ -261,9 +261,6 @@ class ActiveQuery extends Component implements ISqlBuilder */ public function getWith(ModelInterface $model): ModelInterface { - if (empty($this->with)) { - return $model; - } return $model->setWith($this->with); }