diff --git a/src/Fields/Relation.php b/src/Fields/Relation.php index 783f9c9d..e99be184 100644 --- a/src/Fields/Relation.php +++ b/src/Fields/Relation.php @@ -485,7 +485,11 @@ public function resolveRelatableQuery(Request $request, Model $model): Builder public function aggregate(string $fn = 'count', string $column = '*'): static { $this->aggregateResolver = function (Request $request, Builder $query) use ($fn, $column): Builder { - $this->setModelAttribute(sprintf('%s_%s', $this->getRelationName(), $fn)); + $this->setModelAttribute(sprintf( + '%s_%s%s', $this->getRelationName(), + $fn, + $column === '*' ? '' : sprintf('_%s', $column) + )); $this->aggregated = true;