From 24042863acbabdcd0fa1432135a9836467f3bce7 Mon Sep 17 00:00:00 2001 From: Guilherme Blanco Date: Mon, 3 Oct 2011 02:21:14 -0300 Subject: [PATCH] BasicEntityPersister::exists() was not supporting identifiers that are associations. Fixes DDC-1382. --- .../ORM/Persisters/BasicEntityPersister.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php index a093f9a09..700532e3f 100644 --- a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php @@ -747,6 +747,7 @@ class BasicEntityPersister * * @param array $assoc * @param Doctrine\DBAL\Statement $stmt + * * @return array */ private function loadArrayFromStatement($assoc, $stmt) @@ -771,6 +772,8 @@ class BasicEntityPersister * @param array $assoc * @param Doctrine\DBAL\Statement $stmt * @param PersistentCollection $coll + * + * @return array */ private function loadCollectionFromStatement($assoc, $stmt, $coll) { @@ -784,7 +787,8 @@ class BasicEntityPersister } $hydrator = $this->_em->newHydrator(Query::HYDRATE_OBJECT); - $hydrator->hydrateAll($stmt, $rsm, $hints); + + return $hydrator->hydrateAll($stmt, $rsm, $hints); } /** @@ -1179,6 +1183,7 @@ class BasicEntityPersister $sql = $this->_getSQLTableAlias($class->name, $alias == 'r' ? '' : $alias) . '.' . $class->getQuotedColumnName($field, $this->_platform); $columnAlias = $this->_platform->getSQLResultCasing($columnName . $this->_sqlAliasCounter++); + $this->_rsm->addFieldResult($alias, $columnAlias, $field); return $sql . ' AS ' . $columnAlias; @@ -1228,7 +1233,9 @@ class BasicEntityPersister $sql = 'SELECT 1 ' . $this->_platform->appendLockHint($this->getLockTablesSql(), $lockMode) . ($conditionSql ? ' WHERE ' . $conditionSql : '') . ' ' . $lockSql; + list($params, $types) = $this->expandParameters($criteria); + $stmt = $this->_conn->executeQuery($sql, $params, $types); } @@ -1320,7 +1327,8 @@ class BasicEntityPersister public function loadOneToManyCollection(array $assoc, $sourceEntity, PersistentCollection $coll) { $stmt = $this->getOneToManyStatement($assoc, $sourceEntity); - $this->loadCollectionFromStatement($assoc, $stmt, $coll); + + return $this->loadCollectionFromStatement($assoc, $stmt, $coll); } /** @@ -1478,6 +1486,7 @@ class BasicEntityPersister public function exists($entity, array $extraConditions = array()) { $criteria = $this->_class->getIdentifierValues($entity); + if ($extraConditions) { $criteria = array_merge($criteria, $extraConditions); } @@ -1485,7 +1494,9 @@ class BasicEntityPersister $sql = 'SELECT 1' . ' FROM ' . $this->_class->getQuotedTableName($this->_platform) . ' ' . $this->_getSQLTableAlias($this->_class->name) . ' WHERE ' . $this->_getSelectConditionSQL($criteria); - - return (bool) $this->_conn->fetchColumn($sql, array_values($criteria)); + + list($params, $types) = $this->expandParameters($criteria); + + return (bool) $this->_conn->fetchColumn($sql, $params); } }