Use relation multiple times

17. Mai 2022TCATYPO3

https://docs.typo3.org/m/typo3/reference-tca/10.4/en-us/ColumnsConfig/Type/selectSingle.html#mm-opposite-field

https://forge.typo3.org/issues/56061

https://stackoverflow.com/questions/49347845/multiple-use-of-one-mm-table-in-tca

tx_zwbisdreiconference_domain_model_exhibitionbooth.php

<?php
return [
	'columns' => [
		'main_exhibitor' => [
            'label' => 'Hauptaussteller',
            'config' => [
                'type' => 'group',
                'internal_type' => 'db',
                'allowed' => 'tx_zwbisdreiconference_domain_model_exhibitor',
                'foreign_table' => 'tx_zwbisdreiconference_domain_model_exhibitor',
                'foreign_field' => 'exhibiton_booth',
                'MM' => 'tx_zwbisdreiconference_exhibitionbooth_exhibitor_mm',
                'MM_match_fields' => [
                    'fieldname' => 'main_exhibitor'
                ]
            ]
        ],
		'co_exhibitor' => [
            'label' => 'Nebenaussteller',
            'config' => [
                'type' => 'group',
                'internal_type' => 'db',
                'allowed' => 'tx_zwbisdreiconference_domain_model_exhibitor',
                'foreign_table' => 'tx_zwbisdreiconference_domain_model_exhibitor',
                'foreign_field' => 'exhibiton_booth',
                'MM' => 'tx_zwbisdreiconference_exhibitionbooth_exhibitor_mm',
                'MM_match_fields' => [
                    'fieldname' => 'co_exhibitor'
                ]
            ]
        ]
	]
];

tx_zwbisdreiconference_domain_model_exhibitor.php

<?php
return [
	'columns' => [
		'exhibiton_booth' => [
            'label' => '',
            'config' => [
                'type' => 'group',
                'internal_type' => 'db',
                'allowed' => 'tx_zwbisdreiconference_domain_model_exhibitionbooth',
                'foreign_table' => 'tx_zwbisdreiconference_domain_model_exhibitionbooth',
                'MM' => 'tx_zwbisdreiconference_exhibitionbooth_exhibitor_mm',
                'MM_opposite_field' => 'main_exhibitor',
                'MM_oppositeUsage' => [
                    'tx_zwbisdreiconference_domain_model_exhibitionbooth' => ['main_exhibitor', 'co_exhibitor']
                ]
            ]
        ]
	]
];

ext_tables.sql

create table tx_zwbisdreiconference_domain_model_exhibitor
(
	exhibiton_booth	int(11) default '0' not null
);

create table tx_zwbisdreiconference_domain_model_exhibitionbooth
(
	main_exhibitor  int(11) default '0' not null,
	co_exhibitor    int(11) default '0' not null
);

create table tx_zwbisdreiconference_exhibitionbooth_exhibitor_mm
(
	uid_local       int(10) unsigned default '0' NOT NULL,
	uid_foreign     int(10) unsigned default '0' NOT NULL,
	sorting         int(10) unsigned default '0' NOT NULL,
	sorting_foreign int(10) unsigned default '0' NOT NULL,
	fieldname       varchar(64) DEFAULT '' NOT NULL
);