Hi Frans
I have 3 Tables, company, shop and address. Every address and every shop belongs to an company. The address
has a column company
which stores the uid
of a company
(type select in TCA).
A shop has exactly on address, the uid
of this address is sores in the column shop.address
. I have to provide a select box from which the User can select an address
that belongs to se same company
as the shop
does. So I have to configure an additional WHERE in the foreign_table_where
property.
The TCA config for the column shop.address:
'address' => array(
'exclude' => 1,
'label' => 'LLL:EXT:mywachau/Resources/Private/Language/locallang_db.xlf:tx_mywachau_domain_model_shop.address',
'config' => array(
'type' => 'select',
'foreign_table' => 'tx_mywachau_domain_model_address',
'foreign_table_where' => 'AND tx_mywachau_domain_model_address.company=###REC_FIELD_company###',
'minitems' => 0,
'maxitems' => 1,
),
),
The shops of an company are managed bei a TCA column called shop
with the type inline
in the TCA for the table company
.
The TCA for this column company.shop:
'shop' => array(
'exclude' => 1,
'label' => 'LLL:EXT:mywachau/Resources/Private/Language/locallang_db.xlf:tx_mywachau_domain_model_company.shop',
'config' => array(
'type' => 'inline',
'foreign_table' => 'tx_mywachau_domain_model_shop',
'foreign_field' => 'company',
'maxitems' => 9999,
'appearance' => array(
'collapseAll' => 0,
'levelLinksPosition' => 'top',
'showSynchronizationLink' => 1,
'showPossibleLocalizationRecords' => 1,
'showAllLocalizationLink' => 1
),
'foreign_unique' => 'type', // a company can only have one shop of a specific type
'foreign_record_defaults' => array(
'company' => '###PARENT_UID###' // my NEW SOLUTION!!!!!!!!!!!!
),
),
),
Problem¶
Now if you add a new shop to a company a shop record is created and all controlles are rendered for this record, by an AJAX request. The Problem is that the new created record don't have set the correct foreign key value in the column shop.company
. And because of that, an empty list for the address select box is rendered.
If a user want's to add a shop to a company he have to click the Create New Button save the hole company record an only after that he is able to select an address for a shop. Becaus wen the shop record is save for the first time Typo3 of corse writs the correct uid
to the column shop.company
.
With my ###PARENT_UID###
marker I can overcome the problem that an user is force to save a new created inline shop record bevor he really can edit this new shop record.