Bug #103604
closedMM table generation sets wrong PRIMARY KEY for columns with multiple=1
0%
Description
A TCA select column with multiple=1 generates a PRIMARY KEY over the fields `uid_local` and `uid_foreign` of the MM table.
When multiple is active, i can select a record from `tx_tea_domain_model_coffee` multiple times.
When i save the record i get the exception `An exception occurred while executing a query: Duplicate entry '1-2' for key 'tx_tea_tea_coffee_mm.PRIMARY'`
TCA column:
'test' => [ 'exclude' => 1, 'l10n_mode' => 'exclude', 'label' => 'test', 'config' => [ 'type' => 'select', 'renderType' => 'selectMultipleSideBySide', 'foreign_table' => 'tx_tea_domain_model_coffee', 'foreign_table_where' => 'AND tx_tea_domain_model_coffee.sys_language_uid IN (-1,0) Order by title ASC', 'MM' => 'tx_tea_tea_coffee_mm', 'size' => 10, 'autoSizeMax' => 30, 'maxitems' => 9999, 'multiple' => 1, ], ],
Database Analyzer Output:
CREATE TABLE tx_tea_tea_coffee_mm ( uid_local INT UNSIGNED DEFAULT 0 NOT NULL, uid_foreign INT UNSIGNED DEFAULT 0 NOT NULL, sorting INT UNSIGNED DEFAULT 0 NOT NULL, sorting_foreign INT UNSIGNED DEFAULT 0 NOT NULL, INDEX uid_local (uid_local), INDEX uid_foreign (uid_foreign), PRIMARY KEY(uid_local, uid_foreign) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB
Updated by Stefan Bürk 7 months ago
- Status changed from New to Needs Feedback
In TYPO3 v12 the field config MM_hasUidField
is required to be
set in conjuction with multiple = true
for following TCA types
- select
- group
- inline
- category
and only if defined on the local side for a MM relation, which
means the one without the MM_opposite_field
configuration.
Granted, the documentation only mention TCA type group
for
that option [1], which is literally not the complete list.
That means the documentation needs to be corrected if I'm
correct that this options is required.
NOTE: This already changed with TYPO3 v13 where
MM_hasUidField
has
been removed, with Issue #101554 [2] and also related to #101425
for issues with MySQL Galera Clusters.
That means, your TCA configuration should be:
'test' => [
'exclude' => 1,
'l10n_mode' => 'exclude',
'label' => 'test',
'config' => [
'type' => 'select',
'renderType' => 'selectMultipleSideBySide',
'foreign_table' => 'tx_tea_domain_model_coffee',
'foreign_table_where' => 'AND tx_tea_domain_model_coffee.sys_language_uid IN (-1,0) Order by title ASC',
'MM' => 'tx_tea_tea_coffee_mm',
'size' => 10,
'autoSizeMax' => 30,
'maxitems' => 9999,
'multiple' => 1,
'MM_hasUidField' => true, // <--- THIS ONE should be required because of `multiple: 1`
],
],
[1] https://docs.typo3.org/m/typo3/reference-tca/12.4/en-us/ColumnsConfig/Type/Group/Properties/Mm.html#confval-mm-hasuidfield-type-group
[2] Issue #101554 https://review.typo3.org/c/Packages/TYPO3.CMS/+/80434
Updated by Stefan Bürk 7 months ago
- Related to Task #101425: TYPO3 and MariaDB Galera Cluster (PRIMARY KEY) added
- Related to Task #101554: Get rid of MM_hasUidField added
Updated by Garvin Hicking 4 months ago
- Category set to Documentation
- Status changed from Needs Feedback to Closed
There is an Issue in the GitHub docs tracker for this: https://github.com/TYPO3-Documentation/TYPO3CMS-Reference-TCA/issues/1054
I'm closing the issue for this for now, and it will be addressed in docs. Thanks for the good writeup.
(Also closing because of lacking follow-up feedback)