Vtiger_Module_Model->getRelatedModuleRecordIds() returing invalid values
We are migrating a customer from vtiger 6 to vtiger 7 and they noticed something odd. We have a n:n relationship (vtiger_crmentityrel) between 2 vtlib created custom modules: "Contracts" and "Meters".
The code worked fine in vtiger 6, but now, when we call the above function to retrieve the related Meters for this Contract, we get all the Meters but we are also getting Email records too!
This is how vtiger creates the query:
Wed Jun 13 12:15:48 2018,728 [19679] DEBUG VT - Prepared sql query being executed : SELECT relationfieldid,related_tabid
FROM vtiger_relatedlists
WHERE vtiger_relatedlists.tabid=? AND relation_id IN (?)
Wed Jun 13 12:15:48 2018,728 [19679] DEBUG VT - Prepared sql query parameters : [62,254]
Wed Jun 13 12:15:48 2018,729 [19679] DEBUG VT - Prepared sql query being executed : SELECT vtiger_crmentity.crmid FROM vtiger_crmentity INNER JOIN vtiger_crmentityrel ON (vtiger_crment
ityrel.relcrmid = vtiger_crmentity.crmid OR vtiger_crmentityrel.crmid = vtiger_crmentity.crmid)
WHERE (vtiger_crmentityrel.crmid IN (?)) OR (vtiger_crmentityrel.relcrmid IN (?)) AND vtiger_crmentity.deleted = 0
Wed Jun 13 12:15:48 2018,729 [19679] DEBUG VT - Prepared sql query parameters : [3487695,3487695]
It is returning 25 rows, three of which are setype "Emails". Note in the query above there is no check for the module or relmodule column. So this will return all related records - irrespective of which RelationModel I am using to call it:
Here is a snippet of my code:
$relationModel = Vtiger_Relation_Model::getInstanceByModuleName($this->getModule()->getName(), 'LSMeters');
$meterRelationID = $relationModel->getId();
$data = array('related_modules' => array($meterRelationID));
$dummyRequest = new Vtiger_Request($data, $data);
$crmids = $this->getModule()->getRelatedModuleRecordIds($dummyRequest, array($this->getId()));