Commit db1b2d2c authored by alexpott's avatar alexpott

Issue #2192877 by mradcliffe, jhedstrom: File content list includes ambiguous...

Issue #2192877 by mradcliffe, jhedstrom: File content list includes ambiguous column fid in Group By statement
parent 6cfaed4a
......@@ -1266,6 +1266,11 @@ public function query($get_count = FALSE) {
// Add groupby.
if ($groupby) {
foreach ($groupby as $field) {
// Handle group by of field without table alias to avoid ambiguous
// column error.
if ($field == $this->view->storage->get('base_field')) {
$field = $this->view->storage->get('base_table') . '.' . $field;
}
$query->groupBy($field);
}
if (!empty($this->having) && $condition = $this->buildCondition('having')) {
......
......@@ -189,4 +189,20 @@ public function testGroupByCountOnlyFilters() {
$this->assertTrue(strpos($view->build_info['query'], 'HAVING'), 'Make sure that HAVING is in the query');
}
/**
* Tests grouping on base field.
*/
public function testGroupByBaseField() {
$this->setupTestEntities();
$view = Views::getView('test_group_by_count');
$view->setDisplay();
// This tests that the GROUP BY portion of the query is properly formatted
// to include the base table to avoid ambiguous field errors.
$view->displayHandlers->get('default')->options['fields']['name']['group_type'] = 'min';
unset($view->displayHandlers->get('default')->options['fields']['id']['group_type']);
$this->executeView($view);
$this->assertTrue(strpos($view->build_info['query'], 'GROUP BY entity_test.id'), 'GROUP BY field includes the base table name when grouping on the base field.');
}
}
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