Permalink
Browse files

Fixing Query::count() so that formatters added in beforeFind are not

executed
  • Loading branch information...
1 parent 846435b commit aa049950950cb183bc16ba8441ded04b20fe2130 @lorenzo lorenzo committed Jan 25, 2014
Showing with 9 additions and 10 deletions.
  1. +9 −10 src/ORM/Query.php
View
@@ -914,20 +914,19 @@ public function count() {
$count = ['count' => $query->func()->count('*')];
if (!count($query->clause('group')) && !$query->clause('distinct')) {
- return (int)$query
+ $statement = $query
->select($count, true)
- ->hydrate(false)
- ->first()['count'];
+ ->execute();
+ } else {
+ // Forcing at least one field to be selected
+ $query->select($query->newExpr()->add('1'));
+ $statement = $this->connection()->newQuery()
+ ->select($count)
+ ->from(['count_source' => $query])
+ ->execute();
}
- // Forcing at least one field to be selected
- $query->select($query->newExpr()->add('1'));
- $statement = $this->connection()->newQuery()
- ->select($count)
- ->from(['count_source' => $query])
- ->execute();
$result = $statement->fetch('assoc')['count'];
-
$statement->closeCursor();
return (int)$result;
}

0 comments on commit aa04995

Please sign in to comment.