Issue #2192877 by mradcliffe, jhedstrom: File content list includes ambiguous column fid in Group By statement

8.0.x
Alex Pott 2015-02-10 16:22:32 +00:00
parent 6cfaed4a83
commit db1b2d2ca8
2 changed files with 21 additions and 0 deletions

View File

@ -1266,6 +1266,11 @@ class Sql extends QueryPluginBase {
// 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')) {

View File

@ -189,4 +189,20 @@ class QueryGroupByTest extends ViewUnitTestBase {
$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.');
}
}