Skip to content

Commit

Permalink
Renaming Query::total() to Query::count()
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Nov 18, 2013
1 parent 9cc7a05 commit 5b3e31e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
9 changes: 3 additions & 6 deletions Cake/Model/Behavior/CounterCacheBehavior.php
Expand Up @@ -71,11 +71,8 @@
* 'published' => true,
* 'user_id' => $entity->get('user_id')
* ]);
* return $query
* ->select(['count' => $query->count('*')], true)
* ->hydrate(false)
* ->first()['count'];
* }
* return $query->count();
* }
* ]
* ]
* }}}
Expand Down Expand Up @@ -194,6 +191,6 @@ protected function _getCount(array $config, array $conditions) {
$config['conditions'] = array_merge($conditions, $config['conditions']);
$query = $this->_table->find($findType, $config);

return $query->select(['count' => $query->count('*')], true)->hydrate(false)->first()['count'];
return $query->count();
}
}
4 changes: 2 additions & 2 deletions Cake/ORM/Query.php
Expand Up @@ -626,8 +626,8 @@ public function first() {
*
* @return integer
*/
public function total() {
$query = $this->select(['count' => $this->count('*')], true)
public function count() {
$query = $this->select(['count' => $this->func()->count('*')], true)
->hydrate(false);
$query->mapReduce(null, null, true);
return $query->first()['count'];
Expand Down
8 changes: 4 additions & 4 deletions Cake/Test/TestCase/ORM/QueryTest.php
Expand Up @@ -1389,18 +1389,18 @@ public function testHydrateBelongsToCustomEntity() {
}

/**
* Test getting totals from queries.
* Test getting counts from queries.
*
* @return void
*/
public function testTotal() {
public function testCount() {
$table = TableRegistry::get('articles');
$result = $table->find('all')->total();
$result = $table->find('all')->count();
$this->assertEquals(3, $result);

$query = $table->find('all')
->where(['id >' => 1]);
$result = $query->total();
$result = $query->count();
$this->assertEquals(2, $result);

$result = $query->execute();
Expand Down

0 comments on commit 5b3e31e

Please sign in to comment.