mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
N°3660 - Fix JOIN without condition on child joined table is ignored (check done in optimizer)
This commit is contained in:
@@ -331,4 +331,12 @@ class OQLJoin
|
||||
return $this->sRightField;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetLeftField()
|
||||
{
|
||||
return $this->sLeftField;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -294,13 +294,6 @@ class OQLClassTreeBuilder
|
||||
$oClassExpr = new FieldExpression($sClassAttCode, $this->sClassAlias);
|
||||
$oClassRestriction = new BinaryExpression($oClassExpr, 'IN', $oClassListExpr);
|
||||
$oQBContextExpressions->AddCondition($oClassRestriction);
|
||||
} elseif (($oKeyAttDef instanceof AttributeExternalKey) && $sKeyClass != $oKeyAttDef->GetTargetClass()) {
|
||||
$sClassAttCode = 'finalclass';
|
||||
$oClassListExpr = ListExpression::FromScalars(MetaModel::EnumChildClasses($sKeyClass,
|
||||
ENUM_CHILD_CLASSES_ALL));
|
||||
$oClassExpr = new FieldExpression($sClassAttCode, $sKeyClassAlias);
|
||||
$oClassRestriction = new BinaryExpression($oClassExpr, 'IN', $oClassListExpr);
|
||||
$oQBContextExpressions->AddCondition($oClassRestriction);
|
||||
}
|
||||
|
||||
// Translate prior to recursing
|
||||
|
||||
@@ -50,8 +50,15 @@ class OQLClassTreeOptimizer
|
||||
{
|
||||
if ($oJoin->IsOutbound())
|
||||
{
|
||||
// The join is not used, remove from tree
|
||||
$oCurrentClassNode->RemoveJoin($sLeftKey, $index);
|
||||
// If joined class in not the same class than the external key target class
|
||||
// then the join cannot be removed because it is used to filter the request
|
||||
$sJoinedClass = $oJoin->GetOOQLClassNode()->GetNodeClass();
|
||||
$sExtKeyAttCode = $oJoin->GetLeftField();
|
||||
$oExtKeyAttDef = MetaModel::GetAttributeDef($oCurrentClassNode->GetNodeClass(), $sExtKeyAttCode);
|
||||
if ($sJoinedClass == $oExtKeyAttDef->GetTargetClass()) {
|
||||
// The join is not used, remove from tree
|
||||
$oCurrentClassNode->RemoveJoin($sLeftKey, $index);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -441,8 +441,8 @@ class OQLTest extends ItopDataTestCase
|
||||
"SELECT `U` FROM `UserRequest` AS `U`
|
||||
INNER JOIN `lnkContactToTicket` AS `l`
|
||||
ON `U`.`id` = `l`.`ticket_id`
|
||||
INNER JOIN `Contact` AS `T_Contact`
|
||||
ON `l`.`contact_id` = `T_Contact`.`id`",
|
||||
INNER JOIN `Team` AS `T`
|
||||
ON `l`.`contact_id` = `T`.`id`",
|
||||
],
|
||||
'Bug 3660 2' => [
|
||||
"SELECT UserRequest AS U
|
||||
|
||||
Reference in New Issue
Block a user