Feature #82549

Enable support for "real" 1:n relations

Added by Nico de Haen almost 2 years ago. Updated 10 months ago.

Status:
New
Priority:
Should have
Assignee:
-
Category:
DataHandler aka TCEmain
Start date:
2017-09-25
Due date:
% Done:

0%

PHP Version:
Tags:
Complexity:
Sprint Focus:

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...?

History

#1 Updated by Benni Mack over 1 year ago

  • Target version changed from 9.0 to 9 LTS

Hey Nico,

how should the child side in TCA look like?

#2 Updated by Markus Klein over 1 year ago

IMO the child side should be a normal select field on the parent.

#3 Updated by Nico de Haen over 1 year 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,
            ],
        ]

#4 Updated by Nico de Haen over 1 year 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

#5 Updated by Susanne Moog over 1 year ago

  • Category set to DataHandler aka TCEmain

#6 Updated by Oliver Hader over 1 year ago

  • Tracker changed from Task to Feature

#7 Updated by Susanne Moog 10 months ago

  • Target version changed from 9 LTS to Candidate for Major Version

Also available in: Atom PDF