Skip to content

Commit

Permalink
BasicEntityPersister::exists() was not supporting identifiers that ar…
Browse files Browse the repository at this point in the history
…e associations. Fixes DDC-1382.
  • Loading branch information
guilhermeblanco committed Oct 3, 2011
1 parent ebe9338 commit 2404286
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions lib/Doctrine/ORM/Persisters/BasicEntityPersister.php
Expand Up @@ -747,6 +747,7 @@ public function getManyToManyCollection(array $assoc, $sourceEntity, $offset = n
*
* @param array $assoc
* @param Doctrine\DBAL\Statement $stmt
*
* @return array
*/
private function loadArrayFromStatement($assoc, $stmt)
Expand All @@ -771,6 +772,8 @@ private function loadArrayFromStatement($assoc, $stmt)
* @param array $assoc
* @param Doctrine\DBAL\Statement $stmt
* @param PersistentCollection $coll
*
* @return array
*/
private function loadCollectionFromStatement($assoc, $stmt, $coll)
{
Expand All @@ -784,7 +787,8 @@ private function loadCollectionFromStatement($assoc, $stmt, $coll)
}

$hydrator = $this->_em->newHydrator(Query::HYDRATE_OBJECT);
$hydrator->hydrateAll($stmt, $rsm, $hints);

return $hydrator->hydrateAll($stmt, $rsm, $hints);
}

/**
Expand Down Expand Up @@ -1179,6 +1183,7 @@ protected function _getSelectColumnSQL($field, ClassMetadata $class, $alias = 'r
$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;
Expand Down Expand Up @@ -1228,7 +1233,9 @@ public function lock(array $criteria, $lockMode)
$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);
}

Expand Down Expand Up @@ -1320,7 +1327,8 @@ public function getOneToManyCollection(array $assoc, $sourceEntity, $offset = nu
public function loadOneToManyCollection(array $assoc, $sourceEntity, PersistentCollection $coll)
{
$stmt = $this->getOneToManyStatement($assoc, $sourceEntity);
$this->loadCollectionFromStatement($assoc, $stmt, $coll);

return $this->loadCollectionFromStatement($assoc, $stmt, $coll);
}

/**
Expand Down Expand Up @@ -1478,14 +1486,17 @@ private function getIndividualValue($value)
public function exists($entity, array $extraConditions = array())
{
$criteria = $this->_class->getIdentifierValues($entity);

if ($extraConditions) {
$criteria = array_merge($criteria, $extraConditions);
}

$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);
}
}

1 comment on commit 2404286

@guilhermeblanco
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@beberlei Please merge in 2.1 =)

Please sign in to comment.