Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove the override for aggregate query creation #9

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 2 additions & 43 deletions src/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,10 @@
namespace Sofa\Eloquence\Query;

use Sofa\Eloquence\Subquery;
use Illuminate\Database\Query\Builder as BaseBuilder;

class Builder extends \Illuminate\Database\Query\Builder
class Builder extends BaseBuilder
{
/**
* Execute an aggregate function on the database.
*
* @param string $function
* @param array $columns
* @return float|int
*/
public function aggregate($function, $columns = ['*'])
{
$this->aggregate = compact('function', 'columns');

$previousColumns = $this->columns;

if (!$this->from instanceof Subquery) {
// We will also back up the select bindings since the select clause will be
// removed when performing the aggregate function. Once the query is run
// we will add the bindings back onto this query so they can get used.
$previousSelectBindings = $this->bindings['select'];

$this->bindings['select'] = [];
}

$results = $this->get($columns);

// Once we have executed the query, we will reset the aggregate property so
// that more select queries can be executed against the database without
// the aggregate value getting in the way when the grammar builds it.
$this->aggregate = null;

$this->columns = $previousColumns;

if (!$this->from instanceof Subquery) {
$this->bindings['select'] = $previousSelectBindings;
}

if (isset($results[0])) {
$result = array_change_key_case((array) $results[0]);

return $result['aggregate'];
}
}

/**
* Backup some fields for the pagination count.
*
Expand Down