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

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

parent e3d8439e
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -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.'));
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment