Feature #82549
openEnable support for "real" 1:n relations
0%
Description
Currently a true 1:n relation is only configurable as IRRE or with a MM table. It should be possible to configure that only with a foreign key field in the child table.
What you can do is this:
['parent_table']['columns']['children'] => [
'config' => [
'type' => 'select',
'renderType' => 'selectMultipleSideBySide',
'size' => 5,
'maxitems' => 20,
'foreign_table' => 'child_table',
'foreign_field' => 'parent_id'
]
]
But that would result in a comma separated list of UIDs in the children field of the parent, while it should result in all selected children having the UID of the parent in their parent_id field.
TCA documentation does not mention, that it is not possible except with comma separated UIDs in the parents field, which requires an appropriate column type...
It has to be handled if children which are already assigned to other parents should just be reassigned when selected for another parent or if they should only be selectable if they are not yet assigned. A configuration flag like onlyShowUnassigned = true/false would be fine...
Maybe since we have Doctrine now, this is not too hard to implement...?
Updated by Benni Mack about 7 years ago
- Target version changed from 9.0 to 9 LTS
Hey Nico,
how should the child side in TCA look like?
Updated by Markus Klein about 7 years ago
IMO the child side should be a normal select field on the parent.
Updated by Nico de Haen about 7 years ago
I think there are 2 options:
configure the field just as passthrough
['child_table']['columns']['main'] => [
'config' => [
'type' => 'passthrough',
],
]
or as a singleSelect, which would result in a bidirectional relation (default?)
['child_table']['columns']['main'] => [
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'foreign_table' => 'parent_table',
'minitems' => 0,
'maxitems' => 1,
],
]
Updated by Nico de Haen about 7 years ago
In IRRE the 1:n relation without MM table looks like this:
Parent:
['parent_table']['columns']['children'] => [
'config' => [
'type' => 'inline',
'size' => 5,
'maxitems' => 20,
'foreign_table' => 'child_table',
'foreign_field' => 'parent_id',
'foreign_table_field' => 'parent_table'
]
]
Child:
['child_table']['columns'] =>
'main' => [
'config' => [
'type' => 'passthrough',
],
],
'parenttable' => [
'config' => [
'type' => 'passthrough',
],
],
]
But the foreign_table_field is imho not best practice in a relational database, since it makes the relation of the foreign key in `main` column ambiguous
Updated by Susanne Moog about 7 years ago
- Category set to DataHandler aka TCEmain
Updated by Susanne Moog about 6 years ago
- Target version changed from 9 LTS to Candidate for Major Version
Updated by Bastian Stargazer over 3 years ago
+1 upvote for this feature
We had plenty use-cases in the past for 1:n relations which should not be editable by the child-record but only defined in the parent. Sure, the comma-separated list works, but is not useful working with custom queries to join relations.