diff --git a/core/oqlclasstreeoptimizer.class.inc.php b/core/oqlclasstreeoptimizer.class.inc.php index 1e12384e9..4bc070218 100644 --- a/core/oqlclasstreeoptimizer.class.inc.php +++ b/core/oqlclasstreeoptimizer.class.inc.php @@ -55,7 +55,7 @@ class OQLClassTreeOptimizer $sJoinedClass = $oJoin->GetOOQLClassNode()->GetNodeClass(); $sExtKeyAttCode = $oJoin->GetLeftField(); $oExtKeyAttDef = MetaModel::GetAttributeDef($oCurrentClassNode->GetNodeClass(), $sExtKeyAttCode); - if ($sJoinedClass == $oExtKeyAttDef->GetTargetClass()) { + if (($oExtKeyAttDef instanceof AttributeExternalKey) && ($sJoinedClass == $oExtKeyAttDef->GetTargetClass())) { // The join is not used, remove from tree $oCurrentClassNode->RemoveJoin($sLeftKey, $index); } diff --git a/test/core/DBSearchTest.php b/test/core/DBSearchTest.php index abc8a7795..91bfd370f 100644 --- a/test/core/DBSearchTest.php +++ b/test/core/DBSearchTest.php @@ -720,4 +720,19 @@ class DBSearchTest extends ItopDataTestCase /** @var \DBObjectSearch $oNestedSearchInExpression */ self::assertEquals($bAllowAllData, $oNestedSearchInExpression->IsAllDataAllowed(), 'Nested DBSearch AllowData value'); } + + /** + * BUG N°4031 check AttributeObjectKey used in JOIN condition + * @throws \ConfigException + * @throws \CoreException + * @throws \MissingQueryArgument + * @throws \OQLException + */ + public function testAttributeObjectKey() + { + $sQuery = "SELECT II FROM InlineImage AS II JOIN UserRequest AS UR ON II.item_id = UR.id WHERE II.item_class = 'UserRequest'"; + $oSearch = \DBObjectSearch::FromOQL($sQuery); + $oSearch->MakeSelectQuery(); + self::assertTrue(true); + } }