mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
N°8511 - Enhance DBObjectSet to be able to order by id
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user