1
0
mirror of synced 2025-01-30 20:11:49 +03:00

[DDC-952] More fixes

This commit is contained in:
Benjamin Eberlei 2011-03-15 21:34:47 +01:00
parent b3c01903b4
commit 1b46208aa5
3 changed files with 41 additions and 31 deletions

View File

@ -52,7 +52,7 @@ class SimpleObjectHydrator extends AbstractHydrator
protected function _prepare() protected function _prepare()
{ {
if (count($this->_rsm->aliasMap) == 1) { if (count($this->_rsm->aliasMap) == 1) {
$this->class = $this->_em->getClassMetadata(current($this->_rsm->aliasMap)); $this->class = $this->_em->getClassMetadata(reset($this->_rsm->aliasMap));
if ($this->class->inheritanceType !== ClassMetadata::INHERITANCE_TYPE_NONE) { if ($this->class->inheritanceType !== ClassMetadata::INHERITANCE_TYPE_NONE) {
foreach ($this->_rsm->declaringClasses AS $column => $class) { foreach ($this->_rsm->declaringClasses AS $column => $class) {
$this->declaringClasses[$column] = $this->_em->getClassMetadata($class); $this->declaringClasses[$column] = $this->_em->getClassMetadata($class);
@ -72,19 +72,20 @@ class SimpleObjectHydrator extends AbstractHydrator
if ($this->class->inheritanceType == ClassMetadata::INHERITANCE_TYPE_NONE) { if ($this->class->inheritanceType == ClassMetadata::INHERITANCE_TYPE_NONE) {
foreach ($sqlResult as $column => $value) { foreach ($sqlResult as $column => $value) {
if (isset($this->_rsm->fieldMappings[$column])) { if (!isset($cache[$column])) {
$column = $this->_rsm->fieldMappings[$column]; if (isset($this->_rsm->fieldMappings[$column])) {
$field = $this->class->fieldNames[$column]; $cache[$column]['name'] = $this->_rsm->fieldMappings[$column];
if (isset($data[$field])) { $cache[$column]['field'] = true;
$data[$column] = $value;
} else { } else {
$data[$field] = Type::getType($this->class->fieldMappings[$field]['type']) $cache[$column]['name'] = $this->_rsm->metaMappings[$column];
->convertToPHPValue($value, $this->_platform);
} }
} else {
$column = $this->_rsm->metaMappings[$column];
$data[$column] = $value;
} }
if (isset($cache[$column]['field'])) {
$value = Type::getType($this->class->fieldMappings[$cache[$column]['name']]['type'])
->convertToPHPValue($value, $this->_platform);
}
$data[$cache[$column]['name']] = $value;
} }
$entityName = $this->class->name; $entityName = $this->class->name;
} else { } else {
@ -92,25 +93,30 @@ class SimpleObjectHydrator extends AbstractHydrator
$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($this->_rsm->fieldMappings[$column])) { if (!isset($cache[$column])) {
$realColumnName = $this->_rsm->fieldMappings[$column]; if (isset($this->_rsm->fieldMappings[$column])) {
$class = $this->declaringClasses[$column]; $field = $this->_rsm->fieldMappings[$column];
if ($class->name == $entityName || is_subclass_of($entityName, $class->name)) { $class = $this->declaringClasses[$column];
$field = $class->fieldNames[$realColumnName]; if ($class->name == $entityName || is_subclass_of($entityName, $class->name)) {
if (isset($data[$field])) { $cache[$column]['name'] = $field;
$data[$realColumnName] = $value; $cache[$column]['class'] = $class;
} else {
$data[$field] = Type::getType($class->fieldMappings[$field]['type'])
->convertToPHPValue($value, $this->_platform);
} }
} else if (isset($this->_rsm->relationMap[$column])) {
if ($this->_rsm->relationMap[$column] == $entityName || is_subclass_of($entityName, $this->_rsm->relationMap[$column])) {
$cache[$column]['name'] = $field;
}
} else {
$cache[$column]['name'] = $this->_rsm->metaMappings[$column];
} }
} else if (isset($this->_rsm->relationMap[$column])) { }
if ($this->_rsm->relationMap[$column] == $entityName || is_subclass_of($entityName, $this->_rsm->relationMap[$column])) {
$data[$realColumnName] = $value; if (isset($cache[$column]['class'])) {
} $value = Type::getType($cache[$column]['class']->fieldMappings[$cache[$column]['name']]['type'])
} else { ->convertToPHPValue($value, $this->_platform);
$column = $this->_rsm->metaMappings[$column]; }
$data[$realColumnName] = $value;
if (isset($cache[$column])) {
$data[$cache[$column]['name']] = $value;
} }
} }
} }

View File

@ -571,8 +571,12 @@ class BasicEntityPersister
if ($entity !== null) { if ($entity !== null) {
$hints[Query::HINT_REFRESH] = true; $hints[Query::HINT_REFRESH] = true;
} }
$hydrator = $this->_em->newHydrator(Query::HYDRATE_OBJECT); if ($this->_selectJoinSql) {
$hydrator = $this->_em->newHydrator(Query::HYDRATE_OBJECT);
} else {
$hydrator = $this->_em->newHydrator(Query::HYDRATE_SIMPLEOBJECT);
}
$entities = $hydrator->hydrateAll($stmt, $this->_rsm, $hints); $entities = $hydrator->hydrateAll($stmt, $this->_rsm, $hints);
return $entities ? $entities[0] : null; return $entities ? $entities[0] : null;
} }

View File

@ -119,7 +119,7 @@ class TypeTest extends \Doctrine\Tests\OrmFunctionalTestCase
$dateTimeDb = $this->_em->find('Doctrine\Tests\Models\Generic\DateTimeModel', $dateTime->id); $dateTimeDb = $this->_em->find('Doctrine\Tests\Models\Generic\DateTimeModel', $dateTime->id);
$this->assertInstanceOf('DateTime', $dateTime->datetime); $this->assertInstanceOf('DateTime', $dateTimeDb->datetime);
$this->assertEquals('2009-10-02 20:10:52', $dateTimeDb->datetime->format('Y-m-d H:i:s')); $this->assertEquals('2009-10-02 20:10:52', $dateTimeDb->datetime->format('Y-m-d H:i:s'));
} }