1
0
mirror of synced 2025-03-28 10:53:49 +03:00
This commit is contained in:
zYne 2007-04-26 17:42:03 +00:00
parent 9460ff9e2c
commit e81891e310

View File

@ -886,28 +886,29 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
// initialize the base of the subquery // initialize the base of the subquery
$subquery = 'SELECT DISTINCT ' . $primaryKey; $subquery = 'SELECT DISTINCT ' . $primaryKey;
if($this->conn->getDBH()->getAttribute(PDO::ATTR_DRIVER_NAME) == 'pgsql') { if ($this->conn->getDBH()->getAttribute(PDO::ATTR_DRIVER_NAME) == 'pgsql') {
// pgsql needs the order by fields to be preserved in select clause // pgsql needs the order by fields to be preserved in select clause
foreach($this->parts['orderby'] as $part) { foreach ($this->parts['orderby'] as $part) {
$e = explode(' ', $part); $e = explode(' ', $part);
// don't add primarykey column (its already in the select clause) // don't add primarykey column (its already in the select clause)
if($e[0] !== $primaryKey) if ($e[0] !== $primaryKey) {
$subquery .= ', ' . $e[0]; $subquery .= ', ' . $e[0];
}
} }
} }
$subquery .= ' FROM ' . $this->conn->quoteIdentifier($table->getTableName()) . ' ' . $alias; $subquery .= ' FROM ' . $this->conn->quoteIdentifier($table->getTableName()) . ' ' . $alias;
foreach($this->parts['join'] as $parts) { foreach ($this->parts['join'] as $parts) {
foreach($parts as $part) { foreach ($parts as $part) {
// preserve LEFT JOINs only if needed // preserve LEFT JOINs only if needed
if(substr($part,0,9) === 'LEFT JOIN') { if (substr($part,0,9) === 'LEFT JOIN') {
$e = explode(' ', $part); $e = explode(' ', $part);
if( ! in_array($e[3], $this->subqueryAliases) && if ( ! in_array($e[3], $this->subqueryAliases) &&
! in_array($e[2], $this->subqueryAliases)) { ! in_array($e[2], $this->subqueryAliases)) {
continue; continue;
} }