From fb8498e0bdd7035781f8f3c102d66bc595364781 Mon Sep 17 00:00:00 2001 From: zYne Date: Mon, 20 Nov 2006 20:22:53 +0000 Subject: [PATCH] Quick fix for bug found with many-to-many relation fetching and limit --- lib/Doctrine/Query.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/Doctrine/Query.php b/lib/Doctrine/Query.php index bca2f7559..590ecef16 100644 --- a/lib/Doctrine/Query.php +++ b/lib/Doctrine/Query.php @@ -464,11 +464,12 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable { return $q; } /** - * returns the built sql query + * builds the sql query from the given parameters and applies things such as + * column aggregation inheritance and limit subqueries if needed * * @param array $params an array of prepared statement params (needed only in mysql driver * when limit subquery algorithm is used) - * @return string + * @return string the built sql query */ public function getQuery($params = array()) { if(empty($this->parts["select"]) || empty($this->parts["from"])) @@ -560,6 +561,8 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable { * @return string the limit subquery */ public function getLimitSubquery() { + + $k = array_keys($this->tables); $table = $this->tables[$k[0]]; @@ -583,15 +586,15 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable { $subquery .= ' FROM ' . $table->getTableName() . ' ' . $alias; - foreach($this->parts['join'] as $parts) { foreach($parts as $part) { // preserve LEFT JOINs only if needed if(substr($part,0,9) === 'LEFT JOIN') { $e = explode(' ', $part); - if( ! in_array($e[3], $this->subqueryAliases)) + if( ! in_array($e[3], $this->subqueryAliases) && ! in_array($e[2], $this->subqueryAliases)) continue; + } $subquery .= ' '.$part; @@ -1126,7 +1129,7 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable { $assocTableName = $asf->getTableName(); - if( ! $loadFields || $table->usesInheritanceMap()) { + if( ! $loadFields) { $this->subqueryAliases[] = $assocTableName; } $this->parts["join"][$tname][$assocTableName] = $join.$assocTableName . ' ON ' .$tname . '.'