1
0
mirror of synced 2024-12-13 14:56:01 +03:00

DQL ORDER BY now supports ordering by an aggregate value

This commit is contained in:
zYne 2007-01-27 10:50:03 +00:00
parent 84a7fb7973
commit a39199f29d
4 changed files with 35 additions and 6 deletions

View File

@ -85,7 +85,10 @@ abstract class Doctrine_Hydrate extends Doctrine_Access
protected $tableIndexes = array();
protected $pendingAggregates = array();
/**
* @var array $aggregateMap an array containing all aggregate aliases, keys as dql aliases
* and values as sql aliases
*/
protected $aggregateMap = array();
/**
* @var Doctrine_Hydrate_Alias $aliasHandler

View File

@ -76,6 +76,7 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
* @var array $pendingFields
*/
private $pendingFields = array();
/**
* @var integer $type the query type
*
@ -115,6 +116,20 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
$this->isSubquery = (bool) $bool;
return $this;
}
/**
* getAggregateAlias
*
* @return string
*/
public function getAggregateAlias($dqlAlias)
{
if(isset($this->aggregateMap[$dqlAlias])) {
return $this->aggregateMap[$dqlAlias];
}
return null;
}
public function getTableStack()
{
return $this->tableStack;
@ -257,9 +272,11 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
}
}
$this->parts['select'][] = $name . '(' . $distinct . implode(', ', $arglist) . ') AS ' . $tableAlias . '__' . count($this->aggregateMap);
$sqlAlias = $tableAlias . '__' . count($this->aggregateMap);
$this->aggregateMap[] = $table;
$this->parts['select'][] = $name . '(' . $distinct . implode(', ', $arglist) . ') AS ' . $sqlAlias;
$this->aggregateMap[$alias] = $sqlAlias;
$this->neededTables[] = $tableAlias;
}
}

View File

@ -60,9 +60,14 @@ class Doctrine_Query_Orderby extends Doctrine_Query_Part
$r = $alias . '.' . $field;
if (isset($e[1])) {
$r .= ' '.$e[1];
}
} else {
$field = $this->query->getAggregateAlias($e[0]);
$r = $field;
}
if (isset($e[1])) {
$r .= ' '.$e[1];
}
$ret[] = $r;
}

View File

@ -32,6 +32,10 @@
*/
class Doctrine_Query_JoinCondition_TestCase extends Doctrine_UnitTestCase
{
public function prepareData()
{ }
public function prepareTables()
{ }
public function testJoinConditionsAreSupportedForOneToManyLeftJoins()
{
$q = new Doctrine_Query();