Skip to content
Snippets Groups Projects
Commit fbd6ffbf authored by Angie Byron's avatar Angie Byron
Browse files

#1005674 by solotandem: Fixed SelectQuery::countQuery() fails with a group by expression

parent c719b1a5
No related branches found
No related tags found
No related merge requests found
......@@ -1354,7 +1354,7 @@ public function union(SelectQueryInterface $query, $type = '') {
}
public function groupBy($field) {
$this->group[] = $field;
$this->group[$field] = $field;
return $this;
}
......@@ -1362,7 +1362,7 @@ public function countQuery() {
// Create our new query object that we will mutate into a count query.
$count = clone($this);
$group_by = drupal_map_assoc(array_values($count->getGroupBy()));
$group_by = $count->getGroupBy();
if (!$count->distinct) {
// When not executing a distinct query, we can zero-out existing fields
......
......@@ -2033,10 +2033,13 @@ class DatabaseSelectComplexTestCase extends DatabaseTestCase {
$this->assertEqual($count, 3, t('Counted the correct number of records.'));
// Test wth an alias.
// Use a column alias as, without one, the query can succeed for the wrong
// reason.
$query = db_select('test_task');
$pid_field = $query->addField('test_task', 'pid', 'pid_alias');
$query->addExpression('COUNT(test_task.task)', 'count');
$query->groupBy('pid_alias');
$query->orderBy('pid_alias', 'asc');
$count = $query->countQuery()->execute()->fetchField();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment