DQL ORDER BY now supports ordering by an aggregate value
This commit is contained in:
parent
84a7fb7973
commit
a39199f29d
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user