1
0
mirror of synced 2025-01-31 04:21:44 +03:00

DDC-1389 - Add validation for empty discriminator map values

This commit is contained in:
Benjamin Eberlei 2011-10-31 23:35:41 +01:00
parent c965d231b1
commit 4b316ec54f
3 changed files with 20 additions and 1 deletions

View File

@ -14,4 +14,13 @@ class HydrationException extends \Doctrine\ORM\ORMException
return new self("The parent object of entity result with alias '$alias' was not found." return new self("The parent object of entity result with alias '$alias' was not found."
. " The parent alias is '$parentAlias'."); . " The parent alias is '$parentAlias'.");
} }
public static function emptyDiscriminatorValue($dqlAlias)
{
return new self("The DQL alias '" . $dqlAlias . "' contains an entity ".
"of an inheritance hierachy with an empty discriminator value. This means " .
"that the database contains inconsistent data with an empty " .
"discriminator value in a table row."
);
}
} }

View File

@ -202,6 +202,11 @@ class ObjectHydrator extends AbstractHydrator
$className = $this->_rsm->aliasMap[$dqlAlias]; $className = $this->_rsm->aliasMap[$dqlAlias];
if (isset($this->_rsm->discriminatorColumns[$dqlAlias])) { if (isset($this->_rsm->discriminatorColumns[$dqlAlias])) {
$discrColumn = $this->_rsm->metaMappings[$this->_rsm->discriminatorColumns[$dqlAlias]]; $discrColumn = $this->_rsm->metaMappings[$this->_rsm->discriminatorColumns[$dqlAlias]];
if ($data[$discrColumn] === "") {
throw HydrationException::emptyDiscriminatorValue($dqlAlias);
}
$className = $this->_ce[$className]->discriminatorMap[$data[$discrColumn]]; $className = $this->_ce[$className]->discriminatorMap[$data[$discrColumn]];
unset($data[$discrColumn]); unset($data[$discrColumn]);
} }

View File

@ -89,8 +89,13 @@ class SimpleObjectHydrator extends AbstractHydrator
$entityName = $this->class->name; $entityName = $this->class->name;
} else { } else {
$discrColumnName = $this->_platform->getSQLResultCasing($this->class->discriminatorColumn['name']); $discrColumnName = $this->_platform->getSQLResultCasing($this->class->discriminatorColumn['name']);
if ($sqlResult[$discrColumnName] === "") {
throw HydrationException::emptyDiscriminatorValue(key($this->_rsm->aliasMap));
}
$entityName = $this->class->discriminatorMap[$sqlResult[$discrColumnName]]; $entityName = $this->class->discriminatorMap[$sqlResult[$discrColumnName]];
unset($sqlResult[$discrColumnName]); unset($sqlResult[$discrColumnName]);
foreach ($sqlResult as $column => $value) { foreach ($sqlResult as $column => $value) {
if (!isset($cache[$column])) { if (!isset($cache[$column])) {
if (isset($this->_rsm->fieldMappings[$column])) { if (isset($this->_rsm->fieldMappings[$column])) {