AOR_report issue with aliases when report contains joins

I have a report that includes join to a custom module. The alias generated in the sql seems to be wrong causing query to fail. I saw this was reported in other thread but not sure where to put the fix. Below is the SQL. It works fine if prop_property.assigned_user_id =‘xxxxx’ replaced with leads:prop_property_leads.assigned_user_id =‘xxxxx’

So the problem is Alias is not being used but rather just table name. somewhere in AOR_Report.php we need to use right alias . Can someone please point to solution.

SELECT `leads:prop_property_leads`.name AS 'Name0', `leads`.last_name AS 'Last_Name1', `leads`.first_name AS 'First_Name2', `leads`.status AS 'Status3', `leads`.status_description AS 'Status_Description4', `leads`.id AS 'leads_id', `leads:prop_property_leads`.id AS 'leads:prop_property_leads_id' FROM `leads` LEFT JOIN prop_property_leads_c `leads|leads:prop_property_leads` ON `leads`.id=`leads|leads:prop_property_leads`.prop_property_leadsleads_idb AND `leads|leads:prop_property_leads`.deleted=0

LEFT JOIN prop_property `leads:prop_property_leads` ON `leads:prop_property_leads`.id=`leads|leads:prop_property_leads`.prop_property_leadsprop_property_ida AND `leads:prop_property_leads`.deleted=0
 AND ( prop_property.assigned_user_id ='xxxxx'  or  EXISTS (SELECT  1
                  FROM    securitygroups secg
                          INNER JOIN securitygroups_users secu
                            ON secg.id = secu.securitygroup_id
                               AND secu.deleted = 0
                               AND secu.user_id = 'xxxxx'
                          INNER JOIN securitygroups_records secr
                            ON secg.id = secr.securitygroup_id
                               AND secr.deleted = 0
                               AND secr.module = 'prop_Property'
                       WHERE   secr.record_id = `leads:prop_property_leads`.id
                               AND secg.deleted = 0) )  WHERE leads.deleted = 0  AND ( leads.assigned_user_id ='xxxxx'  or  EXISTS (SELECT  1
                  FROM    securitygroups secg
                          INNER JOIN securitygroups_users secu
                            ON secg.id = secu.securitygroup_id
                               AND secu.deleted = 0
                               AND secu.user_id = 'xxxxx'
                          INNER JOIN securitygroups_records secr
                            ON secg.id = secr.securitygroup_id
                               AND secr.deleted = 0
                               AND secr.module = 'Leads'
                       WHERE   secr.record_id = leads.id
                               AND secg.deleted = 0) )  LIMIT 0,20

Where is that “other thread” you mention?

Which database are you using? Brand + version?

Thanks.
Similar Issue on GitHub and other one

I am on suiteCRM 7.10.7 with mysql 5.5.62

I had a look at that file and examined the commits done by Jim Mackin (since that thread mentions he fixed this issue), these seem to be the ones possibly related:

https://github.com/salesagility/SuiteCRM/commit/2cb860535df7ab7ac58f62aa61907d12a08f3956
https://github.com/salesagility/SuiteCRM/commit/6aa20e537d9035f11ad97910256f96b978803780
https://github.com/salesagility/SuiteCRM/commit/ac6e2d22d987dfb843f554de0fd90b648ccbfaf9

However, you will likely find that this code is already in your version of the file, these are all old commits (3, 4 years ago). So the best you can get from this is a notion of which parts of the code are relevant, so you can further debug in your specific case.

My guess is that there is some peculiarity about custom fields that isn’t correctly handled yet…