[BUGFIX] Do not detect single select fields as relation 65/53565/4
authorHelmut Hummel <typo3@helhum.io>
Fri, 21 Jul 2017 15:10:05 +0000 (17:10 +0200)
committerGeorg Ringer <georg.ringer@gmail.com>
Tue, 8 Aug 2017 05:07:36 +0000 (07:07 +0200)
With https://review.typo3.org/50879/ all TCA select fields
are detected as relation to many, even when they are configured
as simple static select.

This leads to the row value to be pre-set as string (to hold comma
separated values), which leads to an exception in MySQL Strict Mode
when the select value field is defined as integer.

Therefore only detect renderType === selectMultipleSideBySide
as relational field

Resolves: #81043
Releases: master, 8.7
Change-Id: I54effaace3eb19034d86a9a74bbd5cc207e867f1
Reviewed-on: https://review.typo3.org/53565
Reviewed-by: Benni Mack <benni@typo3.org>
Reviewed-by: Henning Liebe <h.liebe@neusta.de>
Reviewed-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
Tested-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
typo3/sysext/extbase/Classes/Persistence/Generic/Mapper/DataMapFactory.php
typo3/sysext/extbase/Tests/Unit/Persistence/Generic/Mapper/DataMapFactoryTest.php

index 4113824..1ae0504 100644 (file)
@@ -330,7 +330,14 @@ class DataMapFactory implements \TYPO3\CMS\Core\SingletonInterface
                 $columnMap = $this->setOneToManyRelation($columnMap, $columnConfiguration);
             } elseif (isset($propertyMetaData['type']) && strpbrk($propertyMetaData['type'], '_\\') !== false) {
                 $columnMap = $this->setOneToOneRelation($columnMap, $columnConfiguration);
-            } elseif (isset($columnConfiguration['type']) && $columnConfiguration['type'] === 'select') {
+            } elseif (
+                isset($columnConfiguration['type'], $columnConfiguration['renderType'])
+                && $columnConfiguration['type'] === 'select'
+                && (
+                    $columnConfiguration['renderType'] !== 'selectSingle'
+                    || (isset($columnConfiguration['maxitems']) && $columnConfiguration['maxitems'] > 1)
+                )
+            ) {
                 $columnMap->setTypeOfRelation(ColumnMap::RELATION_HAS_MANY);
             } else {
                 $columnMap->setTypeOfRelation(ColumnMap::RELATION_NONE);
index f6922c2..977ffa9 100644 (file)
@@ -153,6 +153,30 @@ class DataMapFactoryTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
     /**
      * @test
      */
+    public function setRelationsDetectsSelectRenderTypeSingleAsNonRelational()
+    {
+        $columnMap = new \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap('foo', 'foo');
+        $columnConfiguration = [
+            'type' => 'select',
+            'renderType' => 'selectSingle',
+            'items' => [
+                ['One', 1],
+                ['Two', 2],
+                ['Three', 3],
+            ],
+        ];
+        $propertyMetaData = [];
+        $mockDataMapFactory = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory::class, ['setOneToOneRelation', 'setOneToManyRelation', 'setManyToManyRelation'], [], '', false);
+        $mockDataMapFactory->expects($this->never())->method('setOneToOneRelation');
+        $mockDataMapFactory->expects($this->never())->method('setOneToManyRelation');
+        $mockDataMapFactory->expects($this->never())->method('setManyToManyRelation');
+        $actualColumnMap = $mockDataMapFactory->_callRef('setRelations', $columnMap, $columnConfiguration, $propertyMetaData);
+        $this->assertSame($columnMap::RELATION_NONE, $actualColumnMap->getTypeOfRelation());
+    }
+
+    /**
+     * @test
+     */
     public function setRelationsDetectsManyToManyRelationOfTypeSelect()
     {
         $mockColumnMap = $this->createMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::class);