diff --git a/modules/Accounts/models/Module.php b/modules/Accounts/models/Module.php
index 88a859b555b2c8e5deac29e9337876699f06ea4d..ab209ef3f386a99332fdb8bd1eb67bf1b8acb3fa 100644
--- a/modules/Accounts/models/Module.php
+++ b/modules/Accounts/models/Module.php
@@ -78,7 +78,7 @@ class Accounts_Module_Model extends Vtiger_Module_Model {
 	 * @param Vtiger_Module_Model $relatedModule
 	 * @return <String>
 	 */
-	public function getRelationQuery($recordId, $functionName, $relatedModule) {
+	public function getRelationQuery($recordId, $functionName, $relatedModule, $relationId) {
 		if ($functionName === 'get_activities') {
 			$focus = CRMEntity::getInstance($this->getName());
 			$focus->id = $recordId;
@@ -115,7 +115,7 @@ class Accounts_Module_Model extends Vtiger_Module_Model {
 			// There could be more than one contact for an activity.
 			$query .= ' GROUP BY vtiger_activity.activityid';
 		} else {
-			$query = parent::getRelationQuery($recordId, $functionName, $relatedModule);
+			$query = parent::getRelationQuery($recordId, $functionName, $relatedModule, $relationId);
 		}
 
 		return $query;
diff --git a/modules/Contacts/models/Module.php b/modules/Contacts/models/Module.php
index f62a62307b56736a346c82010fbccc41168fe295..3859376a3bad3bf6dfa46c1ed99d882f02fa893e 100644
--- a/modules/Contacts/models/Module.php
+++ b/modules/Contacts/models/Module.php
@@ -228,7 +228,7 @@ class Contacts_Module_Model extends Vtiger_Module_Model {
 	 * @param Vtiger_Module_Model $relatedModule
 	 * @return <String>
 	 */
-	public function getRelationQuery($recordId, $functionName, $relatedModule) {
+	public function getRelationQuery($recordId, $functionName, $relatedModule, $relationId) {
 		if ($functionName === 'get_activities') {
 			$userNameSql = getSqlForNameInDisplayFormat(array('first_name' => 'vtiger_users.first_name', 'last_name' => 'vtiger_users.last_name'), 'Users');
 
@@ -253,7 +253,7 @@ class Contacts_Module_Model extends Vtiger_Module_Model {
 				$query = appendFromClauseToQuery($query, $nonAdminQuery);
 			}
 		} else {
-			$query = parent::getRelationQuery($recordId, $functionName, $relatedModule);
+			$query = parent::getRelationQuery($recordId, $functionName, $relatedModule, $relationId);
 		}
 
 		return $query;
diff --git a/modules/HelpDesk/models/Module.php b/modules/HelpDesk/models/Module.php
index d8ded57a5b66685e7884748a0c8bb5f4bee30172..3cd819dc190e3bce5912b2cc5fb00be347df7f5e 100644
--- a/modules/HelpDesk/models/Module.php
+++ b/modules/HelpDesk/models/Module.php
@@ -142,7 +142,7 @@ class HelpDesk_Module_Model extends Vtiger_Module_Model {
 	 * @param Vtiger_Module_Model $relatedModule
 	 * @return <String>
 	 */
-	public function getRelationQuery($recordId, $functionName, $relatedModule) {
+	public function getRelationQuery($recordId, $functionName, $relatedModule, $relationId) {
 		if ($functionName === 'get_activities') {
 			$userNameSql = getSqlForNameInDisplayFormat(array('first_name' => 'vtiger_users.first_name', 'last_name' => 'vtiger_users.last_name'), 'Users');
 
@@ -166,7 +166,7 @@ class HelpDesk_Module_Model extends Vtiger_Module_Model {
 				$query = appendFromClauseToQuery($query, $nonAdminQuery);
 			}
 		} else {
-			$query = parent::getRelationQuery($recordId, $functionName, $relatedModule);
+			$query = parent::getRelationQuery($recordId, $functionName, $relatedModule, $relationId);
 		}
 
 		return $query;
diff --git a/modules/Inventory/models/Module.php b/modules/Inventory/models/Module.php
index b4222561308a35526290dbbf8c1bc0cb9d619e0e..4ac730147dd3e97f4c782e5f8e2df4e827d1aabe 100644
--- a/modules/Inventory/models/Module.php
+++ b/modules/Inventory/models/Module.php
@@ -62,7 +62,7 @@ class Inventory_Module_Model extends Vtiger_Module_Model {
 	 * @param Vtiger_Module_Model $relatedModule
 	 * @return <String>
 	 */
-	public function getRelationQuery($recordId, $functionName, $relatedModule) {
+	public function getRelationQuery($recordId, $functionName, $relatedModule, $relationId) {
 		if ($functionName === 'get_activities') {
 			$userNameSql = getSqlForNameInDisplayFormat(array('first_name' => 'vtiger_users.first_name', 'last_name' => 'vtiger_users.last_name'), 'Users');
 
@@ -86,7 +86,7 @@ class Inventory_Module_Model extends Vtiger_Module_Model {
 				$query = appendFromClauseToQuery($query, $nonAdminQuery);
 			}
 		} else {
-			$query = parent::getRelationQuery($recordId, $functionName, $relatedModule);
+			$query = parent::getRelationQuery($recordId, $functionName, $relatedModule, $relationId);
 		}
 
 		return $query;
diff --git a/modules/Leads/models/Module.php b/modules/Leads/models/Module.php
index b46e5928488b127f02e9afd473337af5afb5e52c..f7b8b55528dcc62d920d6a7d856e556f5aaff29f 100644
--- a/modules/Leads/models/Module.php
+++ b/modules/Leads/models/Module.php
@@ -275,7 +275,7 @@ class Leads_Module_Model extends Vtiger_Module_Model {
 	 * @param Vtiger_Module_Model $relatedModule
 	 * @return <String>
 	 */
-	public function getRelationQuery($recordId, $functionName, $relatedModule) {
+	public function getRelationQuery($recordId, $functionName, $relatedModule, $relationId) {
 		if ($functionName === 'get_activities') {
 			$userNameSql = getSqlForNameInDisplayFormat(array('first_name' => 'vtiger_users.first_name', 'last_name' => 'vtiger_users.last_name'), 'Users');
 
@@ -299,7 +299,7 @@ class Leads_Module_Model extends Vtiger_Module_Model {
 				$query = appendFromClauseToQuery($query, $nonAdminQuery);
 			}
 		} else {
-			$query = parent::getRelationQuery($recordId, $functionName, $relatedModule);
+			$query = parent::getRelationQuery($recordId, $functionName, $relatedModule, $relationId);
 		}
 
 		return $query;
diff --git a/modules/Potentials/models/Module.php b/modules/Potentials/models/Module.php
index 3fe02a598e4217a5f13871fe33018fd8285cc517..8d61304eceb7d86d94a8a5a37f24c448ed544080 100644
--- a/modules/Potentials/models/Module.php
+++ b/modules/Potentials/models/Module.php
@@ -256,7 +256,7 @@ class Potentials_Module_Model extends Vtiger_Module_Model {
 	 * @param Vtiger_Module_Model $relatedModule
 	 * @return <String>
 	 */
-	public function getRelationQuery($recordId, $functionName, $relatedModule) {
+	public function getRelationQuery($recordId, $functionName, $relatedModule, $relationId) {
 		if ($functionName === 'get_activities') {
 			$userNameSql = getSqlForNameInDisplayFormat(array('first_name' => 'vtiger_users.first_name', 'last_name' => 'vtiger_users.last_name'), 'Users');
 
@@ -280,7 +280,7 @@ class Potentials_Module_Model extends Vtiger_Module_Model {
 				$query = appendFromClauseToQuery($query, $nonAdminQuery);
 			}
 		} else {
-			$query = parent::getRelationQuery($recordId, $functionName, $relatedModule);
+			$query = parent::getRelationQuery($recordId, $functionName, $relatedModule, $relationId);
 		}
 
 		return $query;
diff --git a/modules/Vtiger/models/Module.php b/modules/Vtiger/models/Module.php
index 595b87375108a067203ca794af88857536a04b4b..8ce16d3f2fcc07235e609cd01d7c297aa91fde3c 100644
--- a/modules/Vtiger/models/Module.php
+++ b/modules/Vtiger/models/Module.php
@@ -1491,13 +1491,13 @@ class Vtiger_Module_Model extends Vtiger_Module {
 	 * @param Vtiger_Module_Model $relatedModule
 	 * @return <String>
 	 */
-	public function getRelationQuery($recordId, $functionName, $relatedModule) {
+	public function getRelationQuery($recordId, $functionName, $relatedModule, $relationId) {
 		$relatedModuleName = $relatedModule->getName();
 
 		$focus = CRMEntity::getInstance($this->getName());
 		$focus->id = $recordId;
 
-		$result = $focus->$functionName($recordId, $this->getId(), $relatedModule->getId());
+		$result = $focus->$functionName($recordId, $this->getId(), $relatedModule->getId(), $relationId);
 		$query = $result['query'] .' '. $this->getSpecificRelationQuery($relatedModuleName);
 		$nonAdminQuery = $this->getNonAdminAccessControlQueryForRelation($relatedModuleName);
 
diff --git a/pkg/vtiger/modules/Projects/Project/modules/Project/models/Module.php b/pkg/vtiger/modules/Projects/Project/modules/Project/models/Module.php
index 24ab5f3aa8796b53a113617daacd2c9e6218d93a..acaf367c07ca5c18169f6eef647197ef3986cf1d 100644
--- a/pkg/vtiger/modules/Projects/Project/modules/Project/models/Module.php
+++ b/pkg/vtiger/modules/Projects/Project/modules/Project/models/Module.php
@@ -66,9 +66,9 @@ class Project_Module_Model extends Vtiger_Module_Model {
 	 * @param Vtiger_Module_Model $relatedModule
 	 * @return <String>
 	 */
-	public function getRelationQuery($recordId, $functionName, $relatedModule,$relationId) {
+	public function getRelationQuery($recordId, $functionName, $relatedModule, $relationId) {
 		$relatedModuleName = $relatedModule->getName();
-		$query = parent::getRelationQuery($recordId, $functionName, $relatedModule,$relationId);
+		$query = parent::getRelationQuery($recordId, $functionName, $relatedModule, $relationId);
 		return $query;
 	}