From 319f144826974cdc464cc100b237103c620f59d4 Mon Sep 17 00:00:00 2001 From: li_zechao <14549332+li_zechao@user.noreply.gitee.com> Date: Mon, 21 Oct 2024 19:56:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=9B=B4=E6=8E=A5=E4=BD=BF?= =?UTF-8?q?=E7=94=A8count(model.*)=E5=9C=A8mariadb=E4=B8=AD=E4=BC=9A?= =?UTF-8?q?=E6=8A=A5=E9=94=99=E7=9A=84=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/db/concern/ModelRelationQuery.php | 2 +- src/model/concern/RelationShip.php | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/db/concern/ModelRelationQuery.php b/src/db/concern/ModelRelationQuery.php index e6d92531..61ce197a 100644 --- a/src/db/concern/ModelRelationQuery.php +++ b/src/db/concern/ModelRelationQuery.php @@ -468,7 +468,7 @@ public function withCache(string | array | bool $relation = true, $key = true, $ */ public function withCount(string | array $relation, bool $subQuery = true) { - return $this->withAggregate($relation, 'count', '*', $subQuery); + return $this->withAggregate($relation, 'count', '', $subQuery); } /** diff --git a/src/model/concern/RelationShip.php b/src/model/concern/RelationShip.php index 6b2ff2bf..016f2e6d 100644 --- a/src/model/concern/RelationShip.php +++ b/src/model/concern/RelationShip.php @@ -428,6 +428,8 @@ public function relationCount(Query $query, array $relations, string $aggregate $relation = Str::camel($relation); + $field = $field ?: $this->$relation()->getPk(); + if ($useSubQuery) { $count = $this->$relation()->getRelationCountQuery($closure, $aggregate, $field, $name); } else {