function Sql::getNonAggregates

Same name in other branches
  1. 9 core/modules/views/src/Plugin/views/query/Sql.php \Drupal\views\Plugin\views\query\Sql::getNonAggregates()
  2. 8.9.x core/modules/views/src/Plugin/views/query/Sql.php \Drupal\views\Plugin\views\query\Sql::getNonAggregates()
  3. 11.x core/modules/views/src/Plugin/views/query/Sql.php \Drupal\views\Plugin\views\query\Sql::getNonAggregates()

Returns a list of non-aggregates to be added to the "group by" clause.

Non-aggregates are fields that have no aggregation function (count, sum, etc) applied. Since the SQL standard requires all fields to either have an aggregation function applied, or to be in the GROUP BY clause, Views gathers those fields and adds them to the GROUP BY clause.

Return value

array An array of the fieldnames which are non-aggregates.

1 call to Sql::getNonAggregates()
Sql::query in core/modules/views/src/Plugin/views/query/Sql.php
Generates a query and count query from all of the information supplied.

File

core/modules/views/src/Plugin/views/query/Sql.php, line 1195

Class

Sql
Views query plugin for an SQL query.

Namespace

Drupal\views\Plugin\views\query

Code

protected function getNonAggregates() {
    $non_aggregates = [];
    foreach ($this->fields as $field) {
        $string = '';
        if (!empty($field['table'])) {
            $string .= $field['table'] . '.';
        }
        $string .= $field['field'];
        $fieldname = !empty($field['alias']) ? $field['alias'] : $string;
        if (!empty($field['count'])) {
            // Retained for compatibility.
            $field['function'] = 'count';
        }
        if (!empty($field['function'])) {
            $this->hasAggregate = TRUE;
        }
        elseif (empty($field['table'])) {
            $non_aggregates[] = $fieldname;
        }
        elseif (empty($field['aggregate'])) {
            $non_aggregates[] = $fieldname;
        }
        if ($this->getCountOptimized) {
            // We only want the first field in this case.
            break;
        }
    }
    return $non_aggregates;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.