[+BUGFIX] Extbase (Persistence): Removed testing code accidentally committed to trunk...
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Persistence / Mapper / DataMapper.php
index 86eb86c..5ca4b3f 100644 (file)
@@ -190,7 +190,14 @@ class Tx_Extbase_Persistence_Mapper_DataMapper implements t3lib_Singleton {
                        $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;
@@ -203,10 +210,9 @@ class Tx_Extbase_Persistence_Mapper_DataMapper implements t3lib_Singleton {
                                }
                                break;
                                case (Tx_Extbase_Persistence_PropertyType::REFERENCE):
-                                       if (is_null($row->getValue($columnName))) {
-                                               $propertyValue = NULL;
-                                       } else {
-                                               $fieldValue = $row->getValue($columnMap->getColumnName());
+                                       $propertyValue = $row->getValue($columnName);
+                                       if (!is_null($propertyValue)) {
+                                               $fieldValue = $row->getValue($columnName);
                                                $result = $this->fetchRelated($object, $propertyName, $fieldValue);
                                                $propertyValue = $this->mapResultToPropertyValue($object, $propertyName, $result);
                                        }
@@ -272,7 +278,11 @@ class Tx_Extbase_Persistence_Mapper_DataMapper implements t3lib_Singleton {
                $childSortByFieldName = $columnMap->getChildSortByFieldName();
                if ($columnMap->getTypeOfRelation() === Tx_Extbase_Persistence_Mapper_ColumnMap::RELATION_HAS_ONE) {
                        $query = $queryFactory->create($this->getType($parentObject, $propertyName));
-                       $query->matching($query->withUid(intval($fieldValue)));
+                       if (isset($parentKeyFieldName)) {
+                               $query->matching($query->equals($parentKeyFieldName, $parentObject->getUid()));
+                       } else {
+                               $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
@@ -303,11 +313,24 @@ class Tx_Extbase_Persistence_Mapper_DataMapper implements t3lib_Singleton {
                                Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_JOIN_TYPE_INNER,
                                $joinCondition
                                );
+
                        $query->setSource($source);
                        if (!empty($childSortByFieldName)) {
                                $query->setOrderings(array($relationTableName . '.' . $childSortByFieldName => Tx_Extbase_Persistence_QueryInterface::ORDER_ASCENDING));
                        }
-                       $query->matching($query->equals($parentKeyFieldName, $parentObject->getUid()));
+                       
+                       // 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);
                }
@@ -468,7 +491,7 @@ class Tx_Extbase_Persistence_Mapper_DataMapper implements t3lib_Singleton {
                } else {
                        throw new Tx_Extbase_Persistence_Exception_UnexpectedTypeException('Could not determine the child object object type.', 1251315967);
                }
-               return $elementType;            
+               return $elementType;
        }
 
        /**