Commit cd17761f authored by Taylor Otwell's avatar Taylor Otwell

fix distinct problems in paginator.

parent e89082e3
...@@ -626,12 +626,12 @@ class Query { ...@@ -626,12 +626,12 @@ class Query {
* Get an aggregate value. * Get an aggregate value.
* *
* @param string $aggregator * @param string $aggregator
* @param string $column * @param array $columns
* @return mixed * @return mixed
*/ */
public function aggregate($aggregator, $column) public function aggregate($aggregator, $columns)
{ {
$this->aggregate = compact('aggregator', 'column'); $this->aggregate = compact('aggregator', 'columns');
$sql = $this->grammar->select($this); $sql = $this->grammar->select($this);
...@@ -660,7 +660,7 @@ class Query { ...@@ -660,7 +660,7 @@ class Query {
// we have the count. // we have the count.
list($orderings, $this->orderings) = array($this->orderings, null); list($orderings, $this->orderings) = array($this->orderings, null);
$page = Paginator::page($total = $this->count(), $per_page); $page = Paginator::page($total = $this->count($columns), $per_page);
$this->orderings = $orderings; $this->orderings = $orderings;
...@@ -818,14 +818,9 @@ class Query { ...@@ -818,14 +818,9 @@ class Query {
if (in_array($method, array('count', 'min', 'max', 'avg', 'sum'))) if (in_array($method, array('count', 'min', 'max', 'avg', 'sum')))
{ {
if ($method == 'count') if (count($parameters) == 0) $parameters[0] = '*';
{
return $this->aggregate(strtoupper($method), '*'); return $this->aggregate(strtoupper($method), (array) $parameters[0]);
}
else
{
return $this->aggregate(strtoupper($method), $parameters[0]);
}
} }
throw new \Exception("Method [$method] is not defined on the Query class."); throw new \Exception("Method [$method] is not defined on the Query class.");
......
...@@ -93,7 +93,9 @@ class Grammar extends \Laravel\Database\Grammar { ...@@ -93,7 +93,9 @@ class Grammar extends \Laravel\Database\Grammar {
*/ */
protected function aggregate(Query $query) protected function aggregate(Query $query)
{ {
$column = $this->wrap($query->aggregate['column']); $column = $this->columnize($query->aggregate['columns']);
if ($query->distinct and $column !== '*') $column = 'DISTINCT '.$column;
return 'SELECT '.$query->aggregate['aggregator'].'('.$column.')'; return 'SELECT '.$query->aggregate['aggregator'].'('.$column.')';
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment