[+BUGFIX] Extbase (Persistence): Removed testing code accidentally committed to trunk...
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Persistence / Mapper / DataMapper.php
index 8278d94..5ca4b3f 100644 (file)
@@ -44,7 +44,7 @@ class Tx_Extbase_Persistence_Mapper_DataMapper implements t3lib_Singleton {
        /**
         * @var Tx_Extbase_Persistence_QOM_QueryObjectModelFactory
         */
-       protected $QOMFactory;
+       protected $QomFactory;
 
        /**
         * @var Tx_Extbase_Persistence_Session
@@ -96,16 +96,15 @@ class Tx_Extbase_Persistence_Mapper_DataMapper implements t3lib_Singleton {
        }
 
        /**
-        * Injects the persistence manager
+        * Injects the persistence session
         *
-        * @param Tx_Extbase_Persistence_ManagerInterface $persistenceManager
+        * @param Tx_Extbase_Persistence_Session $persistenceSession
         * @return void
         */
-       public function injectPersistenceManager(Tx_Extbase_Persistence_ManagerInterface $persistenceManager) {
-               $this->QOMFactory = $persistenceManager->getBackend()->getQOMFactory();
-               $this->persistenceSession = $persistenceManager->getSession();
+       public function injectSession(Tx_Extbase_Persistence_Session $persistenceSession) {
+               $this->persistenceSession = $persistenceSession;
        }
-       
+
        /**
         * Injects the Reflection Service
         *
@@ -115,6 +114,16 @@ class Tx_Extbase_Persistence_Mapper_DataMapper implements t3lib_Singleton {
        public function injectReflectionService(Tx_Extbase_Reflection_Service $reflectionService) {
                $this->reflectionService = $reflectionService;
        }
+       
+       /**
+        * Sets the query object model factory
+        *
+        * @param Tx_Extbase_Persistence_QOM_QueryObjectModelFactory $qomFactory
+        * @return void
+        */
+       public function setQomFactory(Tx_Extbase_Persistence_QOM_QueryObjectModelFactory $qomFactory) {
+               $this->qomFactory = $qomFactory;
+       }
 
        /**
         * Maps the (aggregate root) rows and registers them as reconstituted
@@ -138,8 +147,8 @@ class Tx_Extbase_Persistence_Mapper_DataMapper implements t3lib_Singleton {
         * @return object
         */
        protected function mapSingleRow($className, Tx_Extbase_Persistence_RowInterface $row) {
-               if ($this->identityMap->hasIdentifier($row['uid'], $className)) {
-                       $object = $this->identityMap->getObjectByIdentifier($row['uid'], $className);
+               if ($this->identityMap->hasIdentifier($row->getValue('uid'), $className)) {
+                       $object = $this->identityMap->getObjectByIdentifier($row->getValue('uid'), $className);
                } else {
                        $object = $this->createEmptyObject($className);
                        $this->thawProperties($object, $row);
@@ -175,144 +184,206 @@ class Tx_Extbase_Persistence_Mapper_DataMapper implements t3lib_Singleton {
                $className = get_class($object);
                $dataMap = $this->getDataMap($className);
                $properties = $object->_getProperties();
-               $object->_setProperty('uid', $row['uid']);
+               $object->_setProperty('uid', $row->getValue('uid'));
                foreach ($properties as $propertyName => $propertyValue) {
                        if (!$dataMap->isPersistableProperty($propertyName)) continue;
                        $columnMap = $dataMap->getColumnMap($propertyName);
                        $columnName = $columnMap->getColumnName();
                        $propertyValue = NULL;
-                       $propertyType = $columnMap->getPropertyType();                  
+                       
+                       $propertyMetaData = $this->reflectionService->getClassSchema($className)->getProperty($propertyName);
+                       $propertyType = Tx_Extbase_Persistence_PropertyType::valueFromType($propertyMetaData['type']);
+
+                       if ($propertyType == Tx_Extbase_Persistence_PropertyType::UNDEFINED) {
+                               $propertyType = $columnMap->getPropertyType();
+                       }
+
                        switch ($propertyType) {
                                case Tx_Extbase_Persistence_PropertyType::STRING;
                                case Tx_Extbase_Persistence_PropertyType::DATE;
                                case Tx_Extbase_Persistence_PropertyType::LONG;
                                case Tx_Extbase_Persistence_PropertyType::DOUBLE;
                                case Tx_Extbase_Persistence_PropertyType::BOOLEAN;
-                               if (isset($row[$columnName])) {
-                                       $rawPropertyValue = $row[$columnName];
+                               if ($row->hasValue($columnName)) {
+                                       $rawPropertyValue = $row->getValue($columnName);
                                        $propertyValue = $dataMap->convertFieldValueToPropertyValue($propertyType, $rawPropertyValue);
                                }
                                break;
                                case (Tx_Extbase_Persistence_PropertyType::REFERENCE):
-                                       if (!is_null($row[$columnName])) {
-                                               $propertyValue = $this->mapRelatedObjects($object, $propertyName, $row, $columnMap);
-                                       } else {
-                                               $propertyValue = NULL;
+                                       $propertyValue = $row->getValue($columnName);
+                                       if (!is_null($propertyValue)) {
+                                               $fieldValue = $row->getValue($columnName);
+                                               $result = $this->fetchRelated($object, $propertyName, $fieldValue);
+                                               $propertyValue = $this->mapResultToPropertyValue($object, $propertyName, $result);
                                        }
                                        break;
-                                       // FIXME we have an object to handle... -> exception
                                default:
-                                       // SK: We should throw an exception as this point as there was an undefined propertyType we can not handle.
-                                       if (isset($row[$columnName])) {
-                                               $property = $row[$columnName];
-                                               if (is_object($property)) {
-                                                       $propertyValue = $this->mapObject($property);
-                                                       // SK: THIS case can not happen I think. At least $this->mapObject() is not available.
-                                               } else {
-                                                       // SK: This case does not make sense either. $this-mapSingleRow has a different signature
-                                                       $propertyValue = $this->mapSingleRow($className, $property);
-                                               }
-                                       }
+                                       // FIXME throw exception
                                        break;
                        }
-
                        $object->_setProperty($propertyName, $propertyValue);
                }
        }
 
        /**
-        * Maps related objects to an ObjectStorage
+        * Fetches a collection of objects related to a property of a parent object
         *
-        * @param object $parentObject The parent object for the mapping result
-        * @param string $propertyName The target property name for the mapping result
-        * @param Tx_Extbase_Persistence_RowInterface $row The actual database row
-        * @param int $loadingStrategy The loading strategy; one of Tx_Extbase_Persistence_Mapper_ColumnMap::STRATEGY_*
-        * @return array|Tx_Extbase_Persistence_ObjectStorage|Tx_Extbase_Persistence_LazyLoadingProxy|another implementation of a loading strategy
+        * @param Tx_Extbase_DomainObject_AbstractEntity $parentObject The object instance this proxy is part of
+        * @param string $propertyName The name of the proxied property in it's parent
+        * @param mixed $fieldValue The raw field value.
+        * @param Tx_Extbase_Persistence_Mapper_DataMap $dataMap The corresponding Data Map of the property
+        * @return mixed The result
         */
-       protected function mapRelatedObjects(Tx_Extbase_DomainObject_AbstractEntity $parentObject, $propertyName, Tx_Extbase_Persistence_RowInterface $row, Tx_Extbase_Persistence_Mapper_ColumnMap $columnMap) {
-               $dataMap = $this->getDataMap(get_class($parentObject));
-               $columnMap = $dataMap->getColumnMap($propertyName);
-               $targetClassSchema = $this->reflectionService->getClassSchema(get_class($parentObject));
-               $propertyMetaData = $targetClassSchema->getProperty($propertyName);
-               $fieldValue = $row[$columnMap->getColumnName()];
-               if ($columnMap->getLoadingStrategy() === Tx_Extbase_Persistence_Mapper_ColumnMap::STRATEGY_LAZY_PROXY) {
-                       $result = t3lib_div::makeInstance('Tx_Extbase_Persistence_LazyLoadingProxy', $parentObject, $propertyName, $fieldValue, $columnMap);
-               } else {
-                       $queryFactory = t3lib_div::makeInstance('Tx_Extbase_Persistence_QueryFactory');
-                       if ($columnMap->getTypeOfRelation() === Tx_Extbase_Persistence_Mapper_ColumnMap::RELATION_HAS_ONE) {
-                               $query = $queryFactory->create($columnMap->getChildClassName());
-                               // TODO: This is an ugly hack, just ignoring the storage page state from here. Actually, the query settings would have to be passed into the DataMapper, so we can respect
-                               // enableFields and storage page settings.
-                               $query->getQuerySettings()->setRespectStoragePage(FALSE);
-                               $result = current($query->matching($query->withUid((int)$fieldValue))->execute());
-                       } elseif (($columnMap->getTypeOfRelation() === Tx_Extbase_Persistence_Mapper_ColumnMap::RELATION_HAS_MANY) || ($columnMap->getTypeOfRelation() === Tx_Extbase_Persistence_Mapper_ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY)) {
-                               if ($propertyMetaData['lazy'] === TRUE || $columnMap->getLoadingStrategy() === Tx_Extbase_Persistence_Mapper_ColumnMap::STRATEGY_LAZY_STORAGE) {
-                                       $result = new Tx_Extbase_Persistence_LazyObjectStorage($parentObject, $propertyName, $fieldValue, $columnMap);
-                               } else {
-                                       $objects = $this->fetchRelatedObjects($parentObject, $propertyName, $fieldValue, $columnMap);
-                                       if ($propertyMetaData['type'] === 'ArrayObject') {
-                                               $result = new ArrayObject($objects);
-                                       } elseif ($propertyMetaData['type'] === 'Tx_Extbase_Persistence_ObjectStorage' || $propertyMetaData['type'] === 'Tx_Extbase_Persistence_LazyObjectStorage') {
-                                               $result = new Tx_Extbase_Persistence_ObjectStorage();
-                                               foreach ($objects as $object) {
-                                                       $result->attach($object);
-                                               }
-                                       } else {
-                                               $result = $objects;
-                                       }
-                               }
+       public function fetchRelated(Tx_Extbase_DomainObject_AbstractEntity $parentObject, $propertyName, $fieldValue = '', $enableLazyLoading = TRUE) {
+               $columnMap = $this->getDataMap(get_class($parentObject))->getColumnMap($propertyName);
+               $propertyMetaData = $this->reflectionService->getClassSchema(get_class($parentObject))->getProperty($propertyName);
+               if ($enableLazyLoading === TRUE && ($propertyMetaData['lazy'] || ($columnMap->getLoadingStrategy() !== Tx_Extbase_Persistence_Mapper_ColumnMap::STRATEGY_EAGER))) {
+                       if (($propertyMetaData['type'] === 'Tx_Extbase_Persistence_ObjectStorage') || ($columnMap->getLoadingStrategy() === Tx_Extbase_Persistence_Mapper_ColumnMap::STRATEGY_LAZY_STORAGE)) {
+                               $result = t3lib_div::makeInstance('Tx_Extbase_Persistence_LazyObjectStorage', $parentObject, $propertyName, $fieldValue);                               
+                       } else {
+                               $result = t3lib_div::makeInstance('Tx_Extbase_Persistence_LazyLoadingProxy', $parentObject, $propertyName, $fieldValue);
                        }
+               } else {
+                       $result = $this->fetchRelatedEager($parentObject, $propertyName, $fieldValue);
                }
                return $result;
        }
-
+       
        /**
-        * Fetches a collection of objects related to a property of a parent object
+        * Fetches the related objects from the storage backend.
         *
         * @param Tx_Extbase_DomainObject_AbstractEntity $parentObject The object instance this proxy is part of
         * @param string $propertyName The name of the proxied property in it's parent
         * @param mixed $fieldValue The raw field value.
-        * @param Tx_Extbase_Persistence_Mapper_DataMap $dataMap The corresponding Data Map of the property
-        * @return Tx_Extbase_Persistence_ObjectStorage An Object Storage containing the related objects 
+        * @return void
         */
-       public function fetchRelatedObjects(Tx_Extbase_DomainObject_AbstractEntity $parentObject, $propertyName, $fieldValue, Tx_Extbase_Persistence_Mapper_ColumnMap $columnMap) {
+       protected function fetchRelatedEager(Tx_Extbase_DomainObject_AbstractEntity $parentObject, $propertyName, $fieldValue = '') {
+               if ($fieldValue === '') return array();
+               $query = $this->getPreparedQuery($parentObject, $propertyName, $fieldValue);
+               return $query->execute();
+       }
+       
+       /**
+        * Builds and returns the prepared query, ready to be executed.
+        *
+        * @param Tx_Extbase_DomainObject_AbstractEntity $parentObject 
+        * @param string $propertyName 
+        * @param string $fieldValue 
+        * @return void
+        */
+       protected function getPreparedQuery(Tx_Extbase_DomainObject_AbstractEntity $parentObject, $propertyName, $fieldValue = '') {
+               $columnMap = $this->getDataMap(get_class($parentObject))->getColumnMap($propertyName);
                $queryFactory = t3lib_div::makeInstance('Tx_Extbase_Persistence_QueryFactory');
-               $objects = NULL;
-               if ($columnMap->getTypeOfRelation() === Tx_Extbase_Persistence_Mapper_ColumnMap::RELATION_HAS_MANY) {
-                       $query = $queryFactory->create($columnMap->getChildClassName());
-                       $parentKeyFieldName = $columnMap->getParentKeyFieldName();
+               $parentKeyFieldName = $columnMap->getParentKeyFieldName();
+               $childSortByFieldName = $columnMap->getChildSortByFieldName();
+               if ($columnMap->getTypeOfRelation() === Tx_Extbase_Persistence_Mapper_ColumnMap::RELATION_HAS_ONE) {
+                       $query = $queryFactory->create($this->getType($parentObject, $propertyName));
                        if (isset($parentKeyFieldName)) {
-                               $objects = $query->matching($query->equals($columnMap->getParentKeyFieldName(), $parentObject->getUid()))->execute();
+                               $query->matching($query->equals($parentKeyFieldName, $parentObject->getUid()));
                        } else {
-                               $uidArray = t3lib_div::intExplode(',', $fieldValue);
-                               $uids = implode(',', $uidArray);
-                               // FIXME Using statement() is only a preliminary solution
-                               $objects = $query->statement('SELECT * FROM ' . $columnMap->getChildTableName() . ' WHERE uid IN (' . $uids . ')')->execute();
+                               $query->matching($query->withUid(intval($fieldValue)));
+                       }
+               } elseif ($columnMap->getTypeOfRelation() === Tx_Extbase_Persistence_Mapper_ColumnMap::RELATION_HAS_MANY) {
+                       $query = $queryFactory->create($this->getElementType($parentObject, $propertyName));
+                       // TODO: This is an ugly hack, just ignoring the storage page state from here. Actually, the query settings would have to be passed into the DataMapper, so we can respect
+                       // enableFields and storage page settings.
+                       $query->getQuerySettings()->setRespectStoragePage(FALSE);
+                       if (!empty($childSortByFieldName)) {
+                               $query->setOrderings(array($childSortByFieldName => Tx_Extbase_Persistence_QueryInterface::ORDER_ASCENDING));
+                       }
+                       if (isset($parentKeyFieldName)) {
+                               $query->matching($query->equals($parentKeyFieldName, $parentObject->getUid()));
+                       } else {
+                               $query->matching($query->equals('uid', t3lib_div::intExplode(',', $fieldValue)));                                       
                        }
                } elseif ($columnMap->getTypeOfRelation() === Tx_Extbase_Persistence_Mapper_ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY) {
+                       $query = $queryFactory->create($this->getElementType($parentObject, $propertyName));
+                       // TODO: This is an ugly hack, just ignoring the storage page state from here. Actually, the query settings would have to be passed into the DataMapper, so we can respect
+                       // enableFields and storage page settings.
+                       $query->getQuerySettings()->setRespectStoragePage(FALSE);
                        $relationTableName = $columnMap->getRelationTableName();
-                       $left = $this->QOMFactory->selector(NULL, $relationTableName);
-                       $childClassName = $columnMap->getChildClassName();
+                       $left = $this->qomFactory->selector(NULL, $relationTableName);
+                       $childClassName = $this->getElementType($parentObject, $propertyName);
                        $childTableName = $columnMap->getChildTableName();
-                       $right = $this->QOMFactory->selector($childClassName, $childTableName);
-                       $joinCondition = $this->QOMFactory->equiJoinCondition($relationTableName, $columnMap->getChildKeyFieldName(), $childTableName, 'uid');
-                       $source = $this->QOMFactory->join(
+                       $right = $this->qomFactory->selector($childClassName, $childTableName);
+                       $joinCondition = $this->qomFactory->equiJoinCondition($relationTableName, $columnMap->getChildKeyFieldName(), $childTableName, 'uid');
+                       $source = $this->qomFactory->join(
                                $left,
                                $right,
                                Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_JOIN_TYPE_INNER,
                                $joinCondition
                                );
-                       $query = $queryFactory->create($columnMap->getChildClassName());
+
                        $query->setSource($source);
-                       $query->setOrderings(array($columnMap->getChildSortByFieldName() => Tx_Extbase_Persistence_QueryInterface::ORDER_ASCENDING));
-                       // TODO: This is an ugly hack, just ignoring the storage page state from here. Actually, the query settings would have to be passed into the DataMapper, so we can respect
-                       // enableFields and storage page settings.
-                       $query->getQuerySettings()->setRespectStoragePage(FALSE);
-                       $objects = $query->matching($query->equals($columnMap->getParentKeyFieldName(), $parentObject->getUid()))->execute();
+                       if (!empty($childSortByFieldName)) {
+                               $query->setOrderings(array($relationTableName . '.' . $childSortByFieldName => Tx_Extbase_Persistence_QueryInterface::ORDER_ASCENDING));
+                       }
+                       
+                       // attempt to support MM_match_fields
+                       $conditions = $query->equals($parentKeyFieldName, $parentObject->getUid());
+
+                       $relationTableMatchFields = $columnMap->getRelationTableMatchFields();
+                       if (count($relationTableMatchFields)) {
+                               foreach($relationTableMatchFields as $relationTableMatchFieldName => $relationTableMatchFieldValue) {
+                                       $relationMatchCondition = $query->equals($relationTableName . '.' . $relationTableMatchFieldName, $relationTableMatchFieldValue);
+                                       $conditions = $query->logicalAnd($conditions, $relationMatchCondition);
+                               }
+                       }
+                       $query->matching($conditions);
+                       
                } else {
                        throw new Tx_Extbase_Persistence_Exception('Could not determine type of relation.', 1252502725);
                }
-               return $objects;
+               return $query;
+       }
+
+       /**
+        * Returns the given result as property value of the specified property type.
+        *
+        * @param mixed $result The result could be an object or an ObjectStorage 
+        * @param array $propertyMetaData The property meta data
+        * @return void
+        */
+       public function mapResultToPropertyValue(Tx_Extbase_DomainObject_AbstractEntity $parentObject, $propertyName, $result) {
+               if ($result instanceof Tx_Extbase_Persistence_LoadingStrategyInterface) {
+                       $propertyValue = $result;
+               } else {
+                       $propertyMetaData = $this->reflectionService->getClassSchema(get_class($parentObject))->getProperty($propertyName);
+                       $columnMap = $this->getDataMap(get_class($parentObject))->getColumnMap($propertyName);
+                       if (in_array($propertyMetaData['type'], array('array', 'ArrayObject', 'Tx_Extbase_Persistence_ObjectStorage'))) {
+                               $elementType = $this->getElementType($parentObject, $propertyName);
+                               $objects = array();
+                               foreach ($result as $value) {
+                                       $objects[] = $value;
+                               }
+
+                               if ($propertyMetaData['type'] === 'ArrayObject') {
+                                       $propertyValue = new ArrayObject($objects);
+                               } elseif ($propertyMetaData['type'] === 'Tx_Extbase_Persistence_ObjectStorage') {
+                                       $propertyValue = new Tx_Extbase_Persistence_ObjectStorage();
+                                       foreach ($objects as $object) {
+                                               $propertyValue->attach($object);
+                                       }
+                               } else {
+                                       $propertyValue = $objects;
+                               }
+                       } elseif (strpos($propertyMetaData['type'], '_') !== FALSE) {
+                               $propertyValue = current($result);
+                       }
+               }
+               return $propertyValue;
+       }
+       
+       /**
+        * Counts the number of related objects assigned to a property of a parent object
+        *
+        * @param Tx_Extbase_DomainObject_AbstractEntity $parentObject The object instance this proxy is part of
+        * @param string $propertyName The name of the proxied property in it's parent
+        * @param mixed $fieldValue The raw field value.
+        */
+       public function countRelated(Tx_Extbase_DomainObject_AbstractEntity $parentObject, $propertyName, $fieldValue = '') {
+               $query = $this->getPreparedQuery($parentObject, $propertyName, $fieldValue);
+               return $query->count();
        }
 
        /**
@@ -330,7 +401,8 @@ class Tx_Extbase_Persistence_Mapper_DataMapper implements t3lib_Singleton {
 
        /**
         * Returns a data map for a given class name
-        *
+        * 
+        * @param string $className The class name you want to fetch the Data Map for
         * @return Tx_Extbase_Persistence_Mapper_DataMap The data map
         */
        public function getDataMap($className) {
@@ -338,6 +410,7 @@ class Tx_Extbase_Persistence_Mapper_DataMapper implements t3lib_Singleton {
                if (!isset($this->dataMaps[$className])) {
                        // FIXME This is too expensive for table name aliases -> implement a DataMapBuilder (knowing the aliases defined in $TCA)
                        $columnMapping = array();
+                       $tableName = '';
                        $extbaseSettings = Tx_Extbase_Dispatcher::getExtbaseFrameworkConfiguration();
                        if (is_array($extbaseSettings['persistence']['classes'][$className])) {
                                $persistenceSettings = $extbaseSettings['persistence']['classes'][$className];
@@ -347,7 +420,7 @@ class Tx_Extbase_Persistence_Mapper_DataMapper implements t3lib_Singleton {
                                if (is_array($persistenceSettings['mapping']['columns'])) {
                                        $columnMapping = $persistenceSettings['mapping']['columns'];
                                }
-                       } else {
+                       } elseif (class_exists($className)) {
                                foreach (class_parents($className) as $parentClassName) {
                                        $persistenceSettings = $extbaseSettings['persistence']['classes'][$parentClassName];
                                        if (is_array($persistenceSettings)) {
@@ -360,6 +433,8 @@ class Tx_Extbase_Persistence_Mapper_DataMapper implements t3lib_Singleton {
                                        }
                                        break;
                                }
+                       } else {
+                               throw new Tx_Extbase_Persistence_Exception('Could not determine a Data Map for given class name.', 1256067130);
                        }
 
                        $dataMap = new Tx_Extbase_Persistence_Mapper_DataMap($className, $tableName, $columnMapping);
@@ -397,6 +472,48 @@ class Tx_Extbase_Persistence_Mapper_DataMapper implements t3lib_Singleton {
                }
                return Tx_Extbase_Utility_Extension::convertCamelCaseToLowerCaseUnderscored($propertyName);
        }
+       
+       /**
+        * Returns the type of a child object.
+        *
+        * @param Tx_Extbase_DomainObject_AbstractEntity $parentObject The object instance this proxy is part of
+        * @param string $propertyName The name of the proxied property in it's parent
+        * @return string The class name of the child object
+        */
+       protected function getType(Tx_Extbase_DomainObject_AbstractEntity $parentObject, $propertyName) {
+               $propertyMetaData = $this->reflectionService->getClassSchema(get_class($parentObject))->getProperty($propertyName);
+               $columnMap = $this->getDataMap(get_class($parentObject))->getColumnMap($propertyName);
+               $childClassName = $columnMap->getChildClassName();
+               if (!empty($childClassName)) {
+                       $elementType = $childClassName;
+               } elseif (!empty($propertyMetaData['type'])) {
+                       $elementType = $propertyMetaData['type'];
+               } else {
+                       throw new Tx_Extbase_Persistence_Exception_UnexpectedTypeException('Could not determine the child object object type.', 1251315967);
+               }
+               return $elementType;
+       }
+
+       /**
+        * Returns the type of the elements inside an ObjectStorage or array.
+        *
+        * @param Tx_Extbase_DomainObject_AbstractEntity $parentObject The object instance this proxy is part of
+        * @param string $propertyName The name of the proxied property in it's parent
+        * @return string The class name of the elements inside an ObjectStorage
+        */
+       protected function getElementType(Tx_Extbase_DomainObject_AbstractEntity $parentObject, $propertyName) {
+               $propertyMetaData = $this->reflectionService->getClassSchema(get_class($parentObject))->getProperty($propertyName);
+               $columnMap = $this->getDataMap(get_class($parentObject))->getColumnMap($propertyName);
+               $childClassName = $columnMap->getChildClassName();
+               if (!empty($childClassName)) {
+                       $elementType = $childClassName;
+               } elseif (!empty($propertyMetaData['elementType'])) {
+                       $elementType = $propertyMetaData['elementType'];
+               } else {
+                       throw new Tx_Extbase_Persistence_Exception_UnexpectedTypeException('Could not determine the type of the contained objects.', 1251315966);
+               }
+               return $elementType;            
+       }
 
 }
-?>
+?>
\ No newline at end of file