The views_handler_field_entity class does not include the aggregation language when it overrides views_handler_field's query method to add the entity id. This means that it is not possible to remove the entity id in question from the GROUP BY statement when building a view.

Case in point:

I am building a view of a content type which, by way of file_entity and media projects, uses several image files in each node. I am building a view which will return only the first of those for each node, along with title, teaser, etc. However, when selecting the MIN aggregation type for the Rendered File field I am using, it is not removed from the SQL statement's GROUP BY statement as it should be, resulting in multiple rows per node in the result set rather than the desired single row.

file_entity's views_handler_field_file_rendered class is extending views' views_handler_field_entity and inheriting the query method which is missing the aggregation language.

I don't have the history with this code to know if this was done intentionally or not, but I suspect a bug.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

wayneloftus’s picture

By way of illustration, the query method in the parent class looks like this:

...
$params = $this->options['group_type'] != 'group' ? array('function' => $this->options['group_type']) : array();
$this->field_alias = $this->query->add_field($this->table_alias, $this->real_field, NULL, $params);
...

In views_handler_field_entity, it looks like this:

...
$this->base_field = empty($relationship->definition['base field']) ? $table_data['table']['base']['field'] : $relationship->definition['base field'];
...

The $params are not passed to add_field()

wayneloftus’s picture