[+FEATURE] Extbase (Persistence): Support for MM_match_fields and MM_match_table...
authorJochen Rau <j.rau@web.de>
Wed, 20 Jan 2010 10:45:21 +0000 (10:45 +0000)
committerJochen Rau <j.rau@web.de>
Wed, 20 Jan 2010 10:45:21 +0000 (10:45 +0000)
typo3/sysext/extbase/Classes/Persistence/Backend.php
typo3/sysext/extbase/Classes/Persistence/Mapper/DataMap.php
typo3/sysext/extbase/Classes/Persistence/Mapper/DataMapper.php

index 7e7d12e..2a8ac6a 100644 (file)
@@ -692,6 +692,15 @@ class Tx_Extbase_Persistence_Backend implements Tx_Extbase_Persistence_BackendIn
                // if (isset($childTableName)) {
                //      $row['tablenames'] = $childTableName;
                // }
+               
+               // attempt to support MM_insert_fields
+               $relationTableInsertFields = $columnMap->getRelationTableInsertFields();
+               if (count($relationTableInsertFields)) {
+                       foreach($relationTableInsertFields as $insertField => $insertValue) {
+                               $row[$insertField] = $insertValue;
+                       }
+               }
+
                $res = $this->storageBackend->addRow(
                        $relationTableName,
                        $row,
@@ -710,11 +719,20 @@ class Tx_Extbase_Persistence_Backend implements Tx_Extbase_Persistence_BackendIn
                $dataMap = $this->dataMapper->getDataMap(get_class($parentObject));
                $columnMap = $dataMap->getColumnMap($parentPropertyName);
                $relationTableName = $columnMap->getRelationTableName();
+
+               $relationMatchFields = array(
+                       $columnMap->getParentKeyFieldName() => (int)$parentObject->getUid()
+               );
+
+               // attempt to support MM_match_fields
+               $relationTableMatchFields = $columnMap->getRelationTableMatchFields();
+               if (count($relationTableMatchFields)) {
+                       $relationMatchFields = array_merge($relationTableMatchFields,$relationMatchFields);
+               }
+
                $res = $this->storageBackend->removeRow(
                        $relationTableName,
-                       array(
-                               $columnMap->getParentKeyFieldName() => (int)$parentObject->getUid()
-                               ),
+                       $relationMatchFields,
                        FALSE);
                return $res;
        }
index b444127..22cf0b9 100644 (file)
@@ -637,4 +637,4 @@ class Tx_Extbase_Persistence_Mapper_DataMap {
                return $convertedValue;
        }
 
-}
+}
\ No newline at end of file
index 40a0879..36e9c0b 100644 (file)
@@ -302,11 +302,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($relationTableMatchFieldName, $relationTableMatchFieldValue);
+                                       $conditions = $query->logicalAnd($conditions, $relationMatchCondition);
+                               }
+                       }
+                       $query->matching($conditions);
+                       
                } else {
                        throw new Tx_Extbase_Persistence_Exception('Could not determine type of relation.', 1252502725);
                }