N°8511 - Enhance DBObjectSet to be able to order by id

This commit is contained in:
odain
2025-08-18 14:37:48 +02:00
parent e6a0d95cba
commit d80e26791d
2 changed files with 33 additions and 13 deletions

View File

@@ -1087,11 +1087,6 @@ abstract class DBSearch
{
$aOrderSpec[$sSQLExpression] = $bAscending;
}
}
else
{
$aOrderSpec['`'.$sAttClassAlias.$sAttCode.'`'] = $bAscending;
}
// Make sure that the columns used for sorting are present in the loaded columns
if (!is_null($aAttToLoad) && !isset($aAttToLoad[$sAttClassAlias][$sAttCode]))
@@ -1099,6 +1094,11 @@ abstract class DBSearch
$aAttToLoad[$sAttClassAlias][$sAttCode] = MetaModel::GetAttributeDef($sAttClass, $sAttCode);
}
}
else
{
$aOrderSpec['`'.$sAttClassAlias.$sAttCode.'`'] = $bAscending;
}
}
$oSQLQuery = $this->GetSQLQuery($aOrderBy, $aArgs, $aAttToLoad, $aExtendedDataSpec, $iLimitCount, $iLimitStart, $bGetCount);

View File

@@ -88,4 +88,24 @@ class DBSearchCommitTest extends ItopDataTestCase
static::assertEquals(0, $oSet->Count());
}
/**
* @covers N°8511 - Enhance DBObjectSet to be able to order by id
*/
public function testDbObjectSetFetchMethodWorksWithOptimizeColumnLoadOrderedById(){
$sUID=uniqid();
$oOrg1 = $this->CreateOrganization($sUID);
$oOrg2 = $this->CreateOrganization($sUID);
$oSearch = DBSearch::FromOQL("SELECT Organization WHERE name=\"$sUID\"", ['uuid' => $sUID]);
$oSet = new \DBObjectSet($oSearch, ['name' => true, 'id' => false ]);
$oSet->OptimizeColumnLoad(['Organization' => ['name']]);
static::assertEquals(2, $oSet->Count());
static::assertEquals($oOrg2->GetKey(), $oSet->Fetch()->GetKey());
$oSet = new \DBObjectSet($oSearch, ['name' => true, 'id' => true ]);
static::assertEquals(2, $oSet->Count());
static::assertEquals($oOrg1->GetKey(), $oSet->Fetch()->GetKey());
}
}