#1005674 by solotandem: Fixed SelectQuery::countQuery() fails with a group by expression
parent
c719b1a5b3
commit
fbd6ffbf52
|
@ -1354,7 +1354,7 @@ class SelectQuery extends Query implements SelectQueryInterface {
|
|||
}
|
||||
|
||||
public function groupBy($field) {
|
||||
$this->group[] = $field;
|
||||
$this->group[$field] = $field;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -1362,7 +1362,7 @@ class SelectQuery extends Query implements SelectQueryInterface {
|
|||
// 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();
|
||||
|
||||
|
|
Loading…
Reference in New Issue