Commit 8cbf5a50 authored by webchick's avatar webchick
Browse files

#1003860 follow-up by dereine, dmitrig01, chx: Fix count queries with aliases.

parent e3d8439e
......@@ -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 = array_keys($count->getGroupBy());
$group_by = drupal_map_assoc(array_values($count->getGroupBy()));
if (!$count->distinct) {
// When not executing a distinct query, we can zero-out existing fields
......
......@@ -2032,6 +2032,15 @@ class DatabaseSelectComplexTestCase extends DatabaseTestCase {
$count = $query->countQuery()->execute()->fetchField();
$this->assertEqual($count, 3, t('Counted the correct number of records.'));
// Test wth an alias.
$query = db_select('test_task');
$pid_field = $query->addField('test_task', 'pid', 'pid_alias');
$query->groupBy('pid_alias');
$count = $query->countQuery()->execute()->fetchField();
$this->assertEqual($count, 3, t('Counted the correct number of records.'));
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment