Bug #81334
Updated by Stephan Großberndt over 7 years ago
Use a TCA definition defining a select with renderType=selectSingle like <pre> return [ 'ctrl' => [ 'title' => 'tx_myext_table', 'label' => 'my_select_single' ], 'types' => [ '1' => ['showitem' => 'my_select_single'] ], 'columns' => [ 'my_select_single' => [ 'config' => [ 'type' => 'select', 'renderType' => 'selectSingle', 'items' => [ ['A', 0], ['B', 1], ['C', 2] ] ] ] ] ]; </pre> and a ext_tables.sql definition defining the value as integer <pre> CREATE TABLE tx_myext_table ( uid int(10) unsigned NOT NULL auto_increment, pid int(10) unsigned NOT NULL DEFAULT '0', my_select_single tinyint(3) unsigned NOT NULL DEFAULT '0', PRIMARY KEY (uid) ); </pre> Have an according Extbase Model like <pre> class Table extends AbstractEntity { /** * @var int */ protected $mySelectSingle; /** * @return int $mySelectSingle */ public function getMySelectSingle() { return $this->mySelectSingle; } /** * @param int $mySelectSingle * @return void */ public function setMySelectSingle($mySelectSingle) { $this->mySelectSingle = $mySelectSingle; } } </pre> When trying to insert a new Record like <pre> $table = new Table(); $table->setMySelectSingle(1); $tableRepository->add($table); </pre> and having a PostgreSQL database beneath this fails with <pre> #1470230766: SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for integer: »« (More information) </pre> because when persisting the Extbase object this property is seen as a CSV relation in @TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory->setRelations@: DataMapper: <pre> protected function setRelations(ColumnMap $columnMap, $columnConfiguration, $propertyMetaData) { if (isset($columnConfiguration)) { if (isset($columnConfiguration['MM'])) { $columnMap = $this->setManyToManyRelation($columnMap, $columnConfiguration); } elseif (isset($propertyMetaData['elementType'])) { $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') { $columnMap->setTypeOfRelation(ColumnMap::RELATION_HAS_MANY); } else { $columnMap->setTypeOfRelation(ColumnMap::RELATION_NONE); } } else { $columnMap->setTypeOfRelation(ColumnMap::RELATION_NONE); } return $columnMap; } </pre> because type=select always defines the relation to be of type ColumnMap::RELATION_HAS_MANY in <pre> } elseif (isset($columnConfiguration['type']) && $columnConfiguration['type'] === 'select') { $columnMap->setTypeOfRelation(ColumnMap::RELATION_HAS_MANY); </pre> Adding an additional check for renderType=selectSingle fixes this: <pre> } elseif (isset($columnConfiguration['type']) && $columnConfiguration['type'] === 'select' && isset($columnConfiguration['renderType']) && $columnConfiguration['renderType'] === 'selectSingle') { $columnMap->setTypeOfRelation(ColumnMap::RELATION_HAS_ONE); } elseif (isset($columnConfiguration['type']) && $columnConfiguration['type'] === 'select') { $columnMap->setTypeOfRelation(ColumnMap::RELATION_HAS_MANY); </pre>