Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support custom one to many relations in yaml fixtures by nesting entities key #619

Open
nmaier95 opened this issue Sep 6, 2024 · 0 comments · May be fixed by #620
Open

Support custom one to many relations in yaml fixtures by nesting entities key #619

nmaier95 opened this issue Sep 6, 2024 · 0 comments · May be fixed by #620

Comments

@nmaier95
Copy link

nmaier95 commented Sep 6, 2024

Does your feature request relate to a problem?

Currently when writing yaml fixtures for test cases it is possible to model a datastructure by using the entities key. However the relation only correctly resolves when depending on the default pid column (e.g. content elements inside pages, see "example 1").

Example 1

entitySettings:
    '*':
        nodeColumnName: 'pid'
        columnNames: {id: 'uid', language: 'sys_language_uid'}
        defaultValues: {pid: 0}
    page:
        isNode: true
        tableName: 'pages'
        languageColumnNames: ['l10n_parent', 'l10n_source']
        defaultValues: {hidden: 0, doktype: 1}
    content:
        tableName: 'tt_content'
        languageColumnNames: ['l18n_parent', 'l10n_source']

entities:
    page:
        - self: {pid: 1, title: 'Sample Page'}
          entities:
              content:
                  - self: {CType: 'textmedia', header: 'Sample Content'}

Custom data structures with their own arbitrary relations cannot be modeled. Besides by creating them by their own and writing their incremented Uids (see inline_record: 10000 at "example 2") by hand into the relation column which gets very messy when handling many.

Example 2

__variables:
    - &pageStandard 1
    - &siteId 1

entitySettings:
    '*':
        nodeColumnName: 'pid'
        defaultValues: { pid: 0 }
    page:
        isNode: true
        tableName: 'pages'
        parentColumnName: 'pid'
        languageColumnNames: [ 'l10n_parent', 'l10n_source' ]
        columnNames: { type: 'doktype' }
        defaultValues: { hidden: 0, doktype: *pageStandard }
    productDetail:
        isNode: true
        tableName: 'tx_extname_domain_model_productdetail'
        languageColumnNames: [ 'l18n_parent', 'l10n_source' ]
        defaultValues:
            hidden: 0
    productPackageSize:
        tableName: 'tx_extname_domain_model_packagesize'
        languageColumnNames: [ 'l18n_parent', 'l10n_source' ]
        defaultValues:
            hidden: 0

entities:
    page:
        -   self: { pid: *siteId, title: 'Product Page A', type: 103, backendLayout: 'pagets__productPage', inline_record: 10000}
            entities:
                productDetail:
                    -   self: { title: 'Product A' }
                        entities:
                            productPackageSize:
                                -   self:
                                        title: 'Size A'
                                        size: 1
                                -   self:
                                        title: 'Size B'
                                        size: 2

Now lets assume one product may have many packageSizes (like also shown in "example 2"). And the TCA for the relation is configured as followed:

tx_extname_domain_model_productdetail

[...]
'package_sizes' => [
    'label' => 'Package Sizes',
    'config' => [
        'type' => 'inline',
        'foreign_table' => 'tx_extname_domain_model_packagesize',
        'foreign_field' => 'package_size',
        'minitems' => 0,
        'maxitems' => 10,
    ],
],
[...]

tx_extname_domain_model_packagesize

[...]
'product_detail' => [
    'config' => [
        'type' => 'passthrough',
    ],
],
[...]

So each packageSize has the uid of its productDetail set in its column product_detail.

Now to the root cause: The TYPO3\CMS\Core\DataHandling\DataHandler needs these kind of relations to be resolved by having the relation set the other way around. Meaning the datastructure the DataHandler expects needs to be like this:

$data = [
    [...]
    'tx_extname_domain_model_productdetail' => [
        'NEW123456789' => [
            [...]
            'title' => 'Product A',
            'package_sizes' => 'NEW123,NEW321'
        ]
    ],
    'tx_extname_domain_model_packagesize' => [
        'NEW123' => [
            [...]
            'title' => 'Size A',
            'size' => 1
        ],
        'NEW321' => [
            [...]
            'title' => 'Size B',
            'size' => 2
        ]
    ]
];

Where the relation is set on the parent record and not like how it is stored in reality: on the child record.

Preferred Solution

Being able to configure those kind of relations by setting some sort of "parent relation column" in addition to the "pid" inside of the entitySettings of each fixture yaml.

nmaier95 added a commit to nmaier95/testing-framework that referenced this issue Sep 6, 2024
Summary:
Implement support to model custom relations of one-to-many relations
inside fixture yamls by adding a new config field inside `entitySettings` for
each table called `parentRelationColumnName`. When set, the data-array structure
passed to the core `DataHandler` receives the relations like expected.
The field needs to be set on a child record with the name of the parent record
column name of the relation as its value.

Resolves Issue TYPO3#619
nmaier95 added a commit to nmaier95/testing-framework that referenced this issue Sep 6, 2024
Summary:
Implement support to model custom relations of one-to-many relations
inside fixture yamls by adding a new config field inside `entitySettings` for
each table called `parentRelationColumnName`. When set, the data-array structure
passed to the core `DataHandler` receives the relations like expected.
The field needs to be set on a child record with the name of the parent record
column name of the relation as its value.

Resolves TYPO3#619
sbuerk pushed a commit to nmaier95/testing-framework that referenced this issue Sep 29, 2024
Summary:
Implement support to model custom relations of one-to-many relations
inside fixture yamls by adding a new config field inside `entitySettings` for
each table called `parentRelationColumnName`. When set, the data-array structure
passed to the core `DataHandler` receives the relations like expected.
The field needs to be set on a child record with the name of the parent record
column name of the relation as its value.

Resolves Issue TYPO3#619
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant