fix distinct problems in paginator.

This commit is contained in:
Taylor Otwell 2012-02-06 15:28:03 -06:00
parent e89082e3ba
commit cd17761f72
2 changed files with 10 additions and 13 deletions

View File

@ -626,12 +626,12 @@ public function get($columns = array('*'))
* 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 @@ public function paginate($per_page = 20, $columns = array('*'))
// 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 @@ public function __call($method, $parameters)
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.");

View File

@ -93,7 +93,9 @@ protected function selects(Query $query)
*/ */
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.')';
} }