Aggregation with entity reference gives incorrect results

Created on 14 February 2025, 2 months ago

Problem/Motivation

I am upgrading a site to the latest D7 no the final fumes of a contract and have hit a snag. A view that works fine in views 3.20 stopped working in 3.29. I have recreated the issue with a super simple version of the view which just has fields: nid and an entityreference field (user) and aggregation on and that is all. The aggregation setting for the entityreference field is group results together on entity id. I also tried target id and all the other checkboxes which did not change the query at all.

In 3.20 the query is:

SELECT DISTINCT node.nid AS nid, node.language AS node_language, MIN(node.nid) AS nid_1, 'node' AS field_data_field_primary_contact_node_entity_type
FROM
{node} node
LEFT JOIN {field_data_field_primary_contact} field_data_field_primary_contact ON node.nid = field_data_field_primary_contact.entity_id AND (field_data_field_primary_contact.entity_type = 'node' AND field_data_field_primary_contact.deleted = '0')
GROUP BY node.nid, node.language, field_data_field_primary_contact_node_entity_type
LIMIT 50 OFFSET 0

Gives 3011 results.

In 3.29 the query is:

SELECT DISTINCT node.nid AS nid, node.language AS node_language, field_data_field_primary_contact.field_primary_contact_target_id AS field_data_field_primary_contact_field_primary_contact_targe, field_data_field_primary_contact.entity_id AS field_data_field_primary_contact_entity_id, MIN(node.nid) AS nid_1, 'node' AS field_data_field_primary_contact_node_entity_type
FROM
{node} node
LEFT JOIN {field_data_field_primary_contact} field_data_field_primary_contact ON node.nid = field_data_field_primary_contact.entity_id AND (field_data_field_primary_contact.entity_type = 'node' AND field_data_field_primary_contact.deleted = '0')
GROUP BY field_data_field_primary_contact_node_entity_type
LIMIT 50 OFFSET 0

Gives 1 result.

I would appreciate any ideas / guidance on where to look to debug this further. Kind thanks.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

3.29

Component

aggregator data

Created by

🇨🇦Canada joel_osc

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024