1
0
Fork 0
mirror of synced 2025-04-03 13:23:37 +03:00

DDC-1080 - Fix bug with hydration of derived entities/foreign key as primary key.

This commit is contained in:
Benjamin Eberlei 2011-05-17 23:42:24 +02:00
parent 1b4f0a5e1f
commit 9ea03de84f
4 changed files with 19 additions and 31 deletions

View file

@ -195,7 +195,7 @@ abstract class AbstractHydrator
$cache[$key]['fieldName'] = $fieldName; $cache[$key]['fieldName'] = $fieldName;
$cache[$key]['dqlAlias'] = $this->_rsm->columnOwnerMap[$key]; $cache[$key]['dqlAlias'] = $this->_rsm->columnOwnerMap[$key];
$classMetadata = $this->_em->getClassMetadata($this->_rsm->aliasMap[$cache[$key]['dqlAlias']]); $classMetadata = $this->_em->getClassMetadata($this->_rsm->aliasMap[$cache[$key]['dqlAlias']]);
$cache[$key]['isIdentifier'] = $classMetadata->isIdentifier($fieldName); $cache[$key]['isIdentifier'] = isset($this->_rsm->isIdentifierColumn[$cache[$key]['dqlAlias']][$key]);
} }
} }

View file

@ -989,7 +989,7 @@ class BasicEntityPersister
$columnAlias = $srcColumn . $this->_sqlAliasCounter++; $columnAlias = $srcColumn . $this->_sqlAliasCounter++;
$columnList .= $this->_getSQLTableAlias($class->name, ($alias == 'r' ? '' : $alias) ) . ".$srcColumn AS $columnAlias"; $columnList .= $this->_getSQLTableAlias($class->name, ($alias == 'r' ? '' : $alias) ) . ".$srcColumn AS $columnAlias";
$resultColumnName = $this->_platform->getSQLResultCasing($columnAlias); $resultColumnName = $this->_platform->getSQLResultCasing($columnAlias);
$this->_rsm->addMetaResult($alias, $this->_platform->getSQLResultCasing($columnAlias), $srcColumn); $this->_rsm->addMetaResult($alias, $this->_platform->getSQLResultCasing($columnAlias), $srcColumn, isset($assoc['id']) && $assoc['id'] === true);
} }
} }
return $columnList; return $columnList;

View file

@ -112,6 +112,13 @@ class ResultSetMapping
* @var array * @var array
*/ */
public $declaringClasses = array(); public $declaringClasses = array();
/**
* This is necessary to hydrate derivate foreign keys correctly.
*
* @var array
*/
public $isIdentifierColumn = array();
/** /**
* Adds an entity result to this ResultSetMapping. * Adds an entity result to this ResultSetMapping.
@ -381,13 +388,17 @@ class ResultSetMapping
/** /**
* Adds a meta column (foreign key or discriminator column) to the result set. * Adds a meta column (foreign key or discriminator column) to the result set.
* *
* @param $alias * @param string $alias
* @param $columnName * @param string $columnName
* @param $fieldName * @param string $fieldName
* @param bool
*/ */
public function addMetaResult($alias, $columnName, $fieldName) public function addMetaResult($alias, $columnName, $fieldName, $isIdentifierColumn = false)
{ {
$this->metaMappings[$columnName] = $fieldName; $this->metaMappings[$columnName] = $fieldName;
$this->columnOwnerMap[$columnName] = $alias; $this->columnOwnerMap[$columnName] = $alias;
if ($isIdentifierColumn) {
$this->isIdentifierColumn[$alias][$columnName] = true;
}
} }
} }

View file

@ -576,7 +576,7 @@ class SqlWalker implements TreeWalker
$columnAlias = $this->getSQLColumnAlias($srcColumn); $columnAlias = $this->getSQLColumnAlias($srcColumn);
$sql .= ", $sqlTableAlias." . $srcColumn . ' AS ' . $columnAlias; $sql .= ", $sqlTableAlias." . $srcColumn . ' AS ' . $columnAlias;
$columnAlias = $this->_platform->getSQLResultCasing($columnAlias); $columnAlias = $this->_platform->getSQLResultCasing($columnAlias);
$this->_rsm->addMetaResult($dqlAlias, $this->_platform->getSQLResultCasing($columnAlias), $srcColumn); $this->_rsm->addMetaResult($dqlAlias, $this->_platform->getSQLResultCasing($columnAlias), $srcColumn, (isset($assoc['id']) && $assoc['id'] === true));
} }
} }
} }
@ -591,7 +591,7 @@ class SqlWalker implements TreeWalker
$columnAlias = $this->getSQLColumnAlias($srcColumn); $columnAlias = $this->getSQLColumnAlias($srcColumn);
$sql .= ', ' . $sqlTableAlias . '.' . $srcColumn . ' AS ' . $columnAlias; $sql .= ', ' . $sqlTableAlias . '.' . $srcColumn . ' AS ' . $columnAlias;
$columnAlias = $this->_platform->getSQLResultCasing($columnAlias); $columnAlias = $this->_platform->getSQLResultCasing($columnAlias);
$this->_rsm->addMetaResult($dqlAlias, $this->_platform->getSQLResultCasing($columnAlias), $srcColumn); $this->_rsm->addMetaResult($dqlAlias, $this->_platform->getSQLResultCasing($columnAlias), $srcColumn, (isset($assoc['id']) && $assoc['id'] === true));
} }
} }
} }
@ -1021,29 +1021,6 @@ class SqlWalker implements TreeWalker
$this->_rsm->addFieldResult($dqlAlias, $columnAlias, $fieldName, $class->name); $this->_rsm->addFieldResult($dqlAlias, $columnAlias, $fieldName, $class->name);
} }
if ($class->containsForeignIdentifier) {
// Add double entry for association identifier columns to simplify hydrator code
foreach ($class->identifier AS $idField) {
if (isset($class->associationMappings[$idField])) {
if (isset($mapping['inherited'])) {
$tableName = $this->_em->getClassMetadata($mapping['inherited'])->table['name'];
} else {
$tableName = $class->table['name'];
}
if ($beginning) $beginning = false; else $sql .= ', ';
$joinColumnName = $class->associationMappings[$idField]['joinColumns'][0]['name'];
$sqlTableAlias = $this->getSQLTableAlias($tableName, $dqlAlias);
$columnAlias = $this->getSQLColumnAlias($joinColumnName);
$sql .= $sqlTableAlias . '.' . $joinColumnName . ' AS ' . $columnAlias;
$columnAlias = $this->_platform->getSQLResultCasing($columnAlias);
$this->_rsm->addMetaResult($dqlAlias, $columnAlias, $idField);
}
}
}
// Add any additional fields of subclasses (excluding inherited fields) // Add any additional fields of subclasses (excluding inherited fields)
// 1) on Single Table Inheritance: always, since its marginal overhead // 1) on Single Table Inheritance: always, since its marginal overhead
// 2) on Class Table Inheritance only if partial objects are disallowed, // 2) on Class Table Inheritance only if partial objects are disallowed,