diff --git a/src/model/relation/BelongsTo.php b/src/model/relation/BelongsTo.php index 78509b5f..1922f466 100644 --- a/src/model/relation/BelongsTo.php +++ b/src/model/relation/BelongsTo.php @@ -100,7 +100,7 @@ public function getRelationCountQuery(?Closure $closure = null, string $aggregat return $this->query ->whereExp($this->localKey, '=' . $this->parent->getTable(true) . '.' . $this->foreignKey) ->fetchSql() - ->$aggregate($this->localKey); + ->$aggregate($field); } /** diff --git a/src/model/relation/HasMany.php b/src/model/relation/HasMany.php index 4e2150cd..0ab0a85a 100644 --- a/src/model/relation/HasMany.php +++ b/src/model/relation/HasMany.php @@ -183,7 +183,7 @@ public function getRelationCountQuery(?Closure $closure = null, string $aggregat return $this->query->alias($aggregate . '_table') ->whereExp($aggregate . '_table.' . $this->foreignKey, '=' . $this->parent->getTable(true) . '.' . $this->localKey) ->fetchSql() - ->$aggregate($this->localKey); + ->$aggregate($field); } /** diff --git a/src/model/relation/HasOne.php b/src/model/relation/HasOne.php index ce983f29..6a5a56a3 100644 --- a/src/model/relation/HasOne.php +++ b/src/model/relation/HasOne.php @@ -100,7 +100,7 @@ public function getRelationCountQuery(?Closure $closure = null, string $aggregat return $this->query ->whereExp($this->foreignKey, '=' . $this->parent->getTable(true) . '.' . $this->localKey) ->fetchSql() - ->$aggregate($this->localKey); + ->$aggregate($field); } /**