Aggregation Funcion Now Breaks SQL
As of one of the later commits (not sure which), our data processor which used an Aggregation Function field (to count the number of cases for a contact) now fails with a "duplicate column name" error. It looks like it's bringing in the ID field of the table we want to count (which it should do), and worse, naming that field the same name as the Aggregation function field name. So the SQL ends up with two fields with the same name. Here is the error from the civicrm logs:
[debug_info] => SELECT COUNT(*) AS count FROM (SELECT DISTINCT
foundations
.id
AScontact_id
,foundations
.display_name
ASfoundation_name
,foundations_Foundation_Information
.foundation_type_40
ASfoundation_type
,foundations_Foundation_Information
.relevance_level_41
ASrelevance_level
,foundation_info
.entity_id
ASfoundation_infoentity_id
,foundation_info
.tsw_connection_48
ASfoundation_infotsw_connection_48
,contact
.display_name
AStsw_connection_contact_name
,open_grant_cases
.id
ASopen_grants
, COUNT(open_grant_cases
.id
) ASopen_grants
FROMcivicrm_contact
foundations
LEFT JOINcivicrm_value_foundation_in_8
foundations_Foundation_Information
ONfoundations
.id
=foundations_Foundation_Information
.entity_id
LEFT JOINcivicrm_value_foundation_in_8
foundation_info
ONfoundation_info
.entity_id
=foundations
.id
LEFT JOINcivicrm_contact
contact
ONcontact
.id
=foundation_info
.tsw_connection_48
AND (contact
.is_deleted
= 0) LEFT JOIN (SELECT_case
.id
ASid
,_case
.case_type_id
AScase_type_id
,_case
.subject
ASsubject
,_case
.start_date
ASstart_date
,_case
.end_date
ASend_date
,_case
.details
ASdetails
,_case
.status_id
ASstatus_id
,_case
.is_deleted
ASis_deleted
,_case
.created_date
AScreated_date
,_case
.modified_date
ASmodified_date
,_case_contact
.case_id
AScase_contact_case_id
,_case_contact
.contact_id
AScase_contact_contact_id
FROMcivicrm_case
_case
INNER JOINcivicrm_case_contact
_case_contact
ON_case
.id
=_case_contact
.case_id
)open_grant_cases
ONopen_grant_cases
.case_contact_contact_id
=foundations
.id
AND (open_grant_cases
.case_type_id
IN (4) ANDopen_grant_cases
.status_id
IN (5, 1) ANDopen_grant_cases
.is_deleted
= 0) WHERE 1 AND ((foundations
.contact_sub_type
LIKE '%^AFoundation^A%')) ANDfoundations
.is_deleted
= 0 ANDfoundations
.contact_type
= 'Organization' GROUP BYfoundations
.id
,foundations
.display_name
,foundations_Foundation_Information
.foundation_type_40
,foundations_Foundation_Information
.relevance_level_41
ORDER BYrelevance_level
ASC,foundation_name
ASC)count_combined_sql_data_flow
[nativecode=1060 ** Duplicate column name 'open_grants']