#65022Problem with propertyMapper when using custom queries (extbase)
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.
Reviews 0
No change resolves or names this issue in its commit message, and no comment links one.