[BUGFIX] foreign_match_fields not fully supported 20/21120/5
authorStefan Froemken <froemken@gmail.com>
Mon, 7 Oct 2013 11:15:06 +0000 (13:15 +0200)
committerStefan Neufeind <typo3.neufeind@speedpartner.de>
Thu, 14 Nov 2013 21:13:32 +0000 (22:13 +0100)
foreign_match_fields were not fully supported
Resolves: #47694
Relates: #45337
Releases: 6.2, 6.1
Change-Id: I212cbdb5d4a3791c1d8ed1e431007e10dd9f11e8
Reviewed-on: https://review.typo3.org/21120
Reviewed-by: Frans Saris
Tested-by: Frans Saris
Reviewed-by: Stefan Neufeind
Tested-by: Stefan Neufeind
typo3/sysext/extbase/Classes/Persistence/Generic/Backend.php

index 74daf12..d942b98 100644 (file)
@@ -363,7 +363,7 @@ class Backend implements \TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface
                        } elseif ($propertyValue instanceof \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface) {
                                if ($object->_isDirty($propertyName)) {
                                        if ($propertyValue->_isNew()) {
-                                               $this->insertObject($propertyValue);
+                                               $this->insertObject($propertyValue, $object, $propertyName);
                                        }
                                        $row[$columnMap->getColumnName()] = $this->getPlainValue($propertyValue);
                                }
@@ -551,6 +551,10 @@ class Backend implements \TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface
                        if ($parentTableFieldName !== NULL) {
                                $row[$parentTableFieldName] = $parentDataMap->getTableName();
                        }
+                       $relationTableMatchFields = $parentColumnMap->getRelationTableMatchFields();
+                       if (is_array($relationTableMatchFields) && count($relationTableMatchFields)) {
+                               $row = array_merge($relationTableMatchFields, $row);
+                       }
                }
                $childSortByFieldName = $parentColumnMap->getChildSortByFieldName();
                if (!empty($childSortByFieldName)) {
@@ -598,9 +602,11 @@ class Backend implements \TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface
         * Inserts an object in the storage backend
         *
         * @param \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $object The object to be insterted in the storage
+        * @param \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $parentObject The parentobject.
+        * @param string $parentPropertyName
         * @return void
         */
-       protected function insertObject(\TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $object) {
+       protected function insertObject(\TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $object, \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $parentObject = NULL, $parentPropertyName = '') {
                if ($object instanceof \TYPO3\CMS\Extbase\DomainObject\AbstractValueObject) {
                        $result = $this->getUidOfAlreadyPersistedValueObject($object);
                        if ($result !== FALSE) {
@@ -614,6 +620,16 @@ class Backend implements \TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface
                if ($dataMap->getLanguageIdColumnName() !== NULL) {
                        $row[$dataMap->getLanguageIdColumnName()] = -1;
                }
+               if ($parentObject !== NULL && $parentPropertyName) {
+                       $parentColumnDataMap = $this->dataMapper->getDataMap(get_class($parentObject))->getColumnMap($parentPropertyName);
+                       $relationTableMatchFields = $parentColumnDataMap->getRelationTableMatchFields();
+                       if (is_array($relationTableMatchFields) && count($relationTableMatchFields) > 0) {
+                               $row = array_merge($relationTableMatchFields, $row);
+                       }
+                       if ($parentColumnDataMap->getParentKeyFieldName() !== NULL) {
+                               $row[$parentColumnDataMap->getParentKeyFieldName()] = (int)$parentObject->getUid();
+                       }
+               }
                $uid = $this->storageBackend->addRow($dataMap->getTableName(), $row);
                $object->_setProperty('uid', (integer) $uid);
                if ((integer) $uid >= 1) {