Fix hydration of Assoc-Id Entities, duplicate the hydration of the foreign key once for for use with the assoc-entity as a meta-column. Added isIdentifier capabilities to meta columns.
This commit is contained in:
parent
5799e391c6
commit
fb44fa6b5a
@ -190,9 +190,11 @@ abstract class AbstractHydrator
|
||||
continue;
|
||||
} else {
|
||||
// Meta column (has meaning in relational schema only, i.e. foreign keys or discriminator columns).
|
||||
$fieldName = $this->_rsm->metaMappings[$key];
|
||||
$cache[$key]['isMetaColumn'] = true;
|
||||
$cache[$key]['fieldName'] = $this->_rsm->metaMappings[$key];
|
||||
$cache[$key]['fieldName'] = $fieldName;
|
||||
$cache[$key]['dqlAlias'] = $this->_rsm->columnOwnerMap[$key];
|
||||
$cache[$key]['isIdentifier'] = $classMetadata->isIdentifier($fieldName);
|
||||
}
|
||||
}
|
||||
|
||||
@ -203,15 +205,15 @@ abstract class AbstractHydrator
|
||||
|
||||
$dqlAlias = $cache[$key]['dqlAlias'];
|
||||
|
||||
if ($cache[$key]['isIdentifier']) {
|
||||
$id[$dqlAlias] .= '|' . $value;
|
||||
}
|
||||
|
||||
if (isset($cache[$key]['isMetaColumn'])) {
|
||||
$rowData[$dqlAlias][$cache[$key]['fieldName']] = $value;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($cache[$key]['isIdentifier']) {
|
||||
$id[$dqlAlias] .= '|' . $value;
|
||||
}
|
||||
|
||||
$rowData[$dqlAlias][$cache[$key]['fieldName']] = $cache[$key]['type']->convertToPHPValue($value, $this->_platform);
|
||||
|
||||
if ( ! isset($nonemptyComponents[$dqlAlias]) && $value !== null) {
|
||||
|
@ -970,6 +970,27 @@ class SqlWalker implements TreeWalker
|
||||
$this->_rsm->addFieldResult($dqlAlias, $columnAlias, $fieldName, $class->name);
|
||||
}
|
||||
|
||||
// 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)
|
||||
// 1) on Single Table Inheritance: always, since its marginal overhead
|
||||
// 2) on Class Table Inheritance only if partial objects are disallowed,
|
||||
|
@ -79,14 +79,42 @@ class DDC117Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$this->assertType(__NAMESPACE__."\DDC117Article", $dqlRef->source());
|
||||
$this->assertSame($dqlRef, $this->_em->find(__NAMESPACE__."\DDC117Reference", $idCriteria));
|
||||
|
||||
$dqlRef->setDescription("New Description!!");
|
||||
$this->_em->flush();
|
||||
$this->_em->clear();
|
||||
|
||||
$dql = "SELECT r, s FROM ".__NAMESPACE__."\DDC117Reference r JOIN r.source s WHERE s.title = ?1";
|
||||
$dqlRef = $this->_em->createQuery($dql)->setParameter(1, 'Foo')->getSingleResult();
|
||||
|
||||
$this->assertEquals('New Description!!', $dqlRef->getDescription());
|
||||
$this->_em->contains($dqlRef);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-117
|
||||
*/
|
||||
public function testUpdateAssocationEntity()
|
||||
{
|
||||
$idCriteria = array('source' => $this->article1->id(), 'target' => $this->article2->id());
|
||||
|
||||
$mapRef = $this->_em->find(__NAMESPACE__."\DDC117Reference", $idCriteria);
|
||||
$mapRef->setDescription("New Description!!");
|
||||
$this->_em->flush();
|
||||
$this->_em->clear();
|
||||
|
||||
$mapRef = $this->_em->find(__NAMESPACE__."\DDC117Reference", $idCriteria);
|
||||
|
||||
$this->assertEquals('New Description!!', $mapRef->getDescription());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-117
|
||||
*/
|
||||
public function testFetchDql()
|
||||
{
|
||||
$dql = "SELECT r, s FROM ".__NAMESPACE__."\DDC117Reference r JOIN r.source s WHERE s.title = ?1";
|
||||
$refs = $this->_em->createQuery($dql)->setParameter(1, 'Foo')->getResult();
|
||||
|
||||
$this->assertTrue(count($refs) > 0, "Has to contain at least one Reference.");
|
||||
foreach ($refs AS $ref) {
|
||||
$this->assertType(__NAMESPACE__."\DDC117Reference", $ref, "Contains only Reference instances.");
|
||||
$this->assertTrue($this->_em->contains($ref), "Contains Reference in the IdentityMap.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user