Skip to content

Commit

Permalink
Wrap column in aggregate function (#35004)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebdesign authored Oct 28, 2020
1 parent 96d0053 commit 50fd3c6
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -381,11 +381,15 @@ public function withAggregate($relations, $column, $function = null)

$relation = $this->getRelationWithoutConstraints($name);

$expression = $function
? sprintf('%s(%s)', $function, $this->getGrammar()->wrap($column))
: $column;

// Here, we will grab the relationship sub-query and prepare to add it to the main query
// as a sub-select. First, we'll get the "has" query and use that to get the relation
// sub-query. We'll format this relationship name and append this column if needed.
$query = $relation->getRelationExistenceQuery(
$relation->getRelated()->newQuery(), $this, new Expression($function ? "$function($column)" : $column)
$relation->getRelated()->newQuery(), $this, new Expression($expression)
)->setBindings([], 'select');

$query->callScope($constraints);
Expand Down

0 comments on commit 50fd3c6

Please sign in to comment.