Skip to content

Commit

Permalink
if count will return more than 1 record, it will return sum of all.
Browse files Browse the repository at this point in the history
  • Loading branch information
basuke authored and Yosuke Basuke Suzuki committed Sep 7, 2011
1 parent 9a02111 commit daaf36f
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions cake/libs/model/model.php
Original file line number Diff line number Diff line change
Expand Up @@ -2408,10 +2408,14 @@ protected function _findCount($state, $query, $results = array()) {
$query['order'] = false;
return $query;
} elseif ($state === 'after') {
if (isset($results[0][0]['count'])) {
return intval($results[0][0]['count']);
} elseif (isset($results[0][$this->alias]['count'])) {
return intval($results[0][$this->alias]['count']);
foreach (array(0, $this->alias) as $key) {
if (isset($results[0][$key]['count'])) {
if (count($results) > 1) {
return intval(array_sum(Set::extract('/' . $key . '/count', $results)));
} else {
return intval($results[0][$key]['count']);
}
}
}
return false;
}
Expand Down

0 comments on commit daaf36f

Please sign in to comment.