Skip to content

Commit

Permalink
Fixing Query::count() so that formatters added in beforeFind are not
Browse files Browse the repository at this point in the history
executed
  • Loading branch information
lorenzo committed Jan 26, 2014
1 parent 846435b commit aa04995
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/ORM/Query.php
Expand Up @@ -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;
}
Expand Down

0 comments on commit aa04995

Please sign in to comment.