From 5299bd788f7afa8bee9a251f6efa99fb64742ffe Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Thu, 30 Jun 2011 21:04:46 +0200 Subject: [PATCH] DDC-1239 - Fix missing AND in Eager LEFT JOIN of entity persister when multiple join columns are used --- lib/Doctrine/ORM/Persisters/BasicEntityPersister.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php index 5ce7080c2..2ee3cf4fe 100644 --- a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php @@ -953,12 +953,17 @@ class BasicEntityPersister } } $this->_selectJoinSql .= ' LEFT JOIN'; // TODO: Inner join when all join columns are NOT nullable. + $first = true; if ($assoc['isOwningSide']) { $this->_selectJoinSql .= ' ' . $eagerEntity->table['name'] . ' ' . $this->_getSQLTableAlias($eagerEntity->name, $assocAlias) .' ON '; foreach ($assoc['sourceToTargetKeyColumns'] AS $sourceCol => $targetCol) { + if (!$first) { + $this->_selectJoinSql .= ' AND '; + } $this->_selectJoinSql .= $this->_getSQLTableAlias($assoc['sourceEntity']) . '.'.$sourceCol.' = ' . $this->_getSQLTableAlias($assoc['targetEntity'], $assocAlias) . '.'.$targetCol.' '; + $first = false; } } else { $eagerEntity = $this->_em->getClassMetadata($assoc['targetEntity']); @@ -967,8 +972,12 @@ class BasicEntityPersister $this->_selectJoinSql .= ' ' . $eagerEntity->table['name'] . ' ' . $this->_getSQLTableAlias($eagerEntity->name, $assocAlias) .' ON '; foreach ($owningAssoc['sourceToTargetKeyColumns'] AS $sourceCol => $targetCol) { + if (!$first) { + $this->_selectJoinSql .= ' AND '; + } $this->_selectJoinSql .= $this->_getSQLTableAlias($owningAssoc['sourceEntity'], $assocAlias) . '.'.$sourceCol.' = ' . $this->_getSQLTableAlias($owningAssoc['targetEntity']) . '.' . $targetCol . ' '; + $first = false; } } }