Actions
Bug #65022
closedProblem with propertyMapper when using custom queries (extbase)
Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Extbase
Target version:
-
Start date:
2015-02-12
Due date:
% Done:
0%
Estimated time:
TYPO3 Version:
6.2
PHP Version:
Tags:
Complexity:
Is Regression:
No
Sprint Focus:
Description
I just wrote an extension and tried to select some addtional data:
// Repository: $sql = 'select *, min(columnname) as fictionalcolumn'; // and so on... return $query->statement($sql)->execute();
And I added the fictionalcolumn to the model (declared as string with getter and setter).
But when I tried to use the fictionalcolumn in my template, it was empty. I investigated the problem with the help of Dennis Römmich (thanks!) and he found the cause at typo3/sysext/extbase/Classes/Persistence/Generic/Mapper/DataMapper.php - function mapSingleRow().
/** * Maps a single row on an object of the given class * * @param string $className The name of the target class * @param array $row A single array with field_name => value pairs * @return object An object of the given class */ protected function mapSingleRow($className, array $row) { if ($this->identityMap->hasIdentifier($row['uid'], $className)) { $object = $this->identityMap->getObjectByIdentifier($row['uid'], $className); } else { $object = $this->createEmptyObject($className); $this->identityMap->registerObject($object, $row['uid']); $this->thawProperties($object, $row); $object->_memorizeCleanState(); $this->persistenceSession->registerReconstitutedEntity($object); } return $object; }
Because there is an uid in the DB result, the data from $row is not used anymore. Thus the value from fictionalcolumn gets lost. Maybe a call to thawProperties() in the if-branch would solve the problem.
Until then, a workaround could be to call $query->getQuerySettings()->setReturnRawQueryResult(TRUE); in the repository before executing the query.
Actions