Actions
Bug #81334
closedSQL-Error inserting renderType=selectSingle via Extbase on PostgreSQL
Start date:
2017-05-24
Due date:
% Done:
0%
Estimated time:
TYPO3 Version:
8
PHP Version:
Tags:
Complexity:
easy
Is Regression:
Sprint Focus:
Description
Use a TCA definition defining a select with renderType=selectSingle like
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] ] ] ] ] ];
and a ext_tables.sql definition defining the value as integer
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) );
Have an according Extbase Model like
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; } }
When trying to insert a new Record like
$table = new Table(); $table->setMySelectSingle(1); $tableRepository->add($table);
and having a PostgreSQL database beneath this fails with
#1470230766: SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for integer: »« (More information)
because when persisting the Extbase object this property is seen as a CSV relation in TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory->setRelations
:
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; }
because type=select always defines the relation to be of type ColumnMap::RELATION_HAS_MANY in
} elseif (isset($columnConfiguration['type']) && $columnConfiguration['type'] === 'select') { $columnMap->setTypeOfRelation(ColumnMap::RELATION_HAS_MANY);
Adding an additional check for renderType=selectSingle fixes this:
} 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);
Actions