【问题标题】:TYPO3 IRRE 1:n delete child records doesn't workTYPO3 IRRE 1:n 删除子记录不起作用
【发布时间】:2017-07-25 07:49:34
【问题描述】:

我是 TYPO3 的新手,我没有太多经验。我正在使用官方文档。 TYPO3 版本 7.6 LTS。

我创建了 1:n 关系。几乎一切正常,子项目被保存和加载,没有任何问题。不过,我有删除的问题。当我删除父实体时,它的子实体没有被删除,这真的很痛苦。

这是我对两个表的 TCA 配置(我已删除不相关的列):

tx_myext_domain_model_item父表:


<?php

$ll = 'LLL:EXT:myext/Resources/Private/Language/locallang_db.xlf:';

return [
    'ctrl' => [
        'title' => $ll . 'basket.item',
        'label' => 'title',
        'tstamp' => 'updated_at',
        'crdate' => 'created_at',
        'cruser_id' => 'user_id'
    ],
    'interface' => [
        'showRecordFieldList' => ''
    ],
    'columns' => [
        'pid' => [
            'label' => $ll . 'pid',
            'config' => [
                'type' => 'passthrough',
            ]
        ],
        // ...
        'documents' => [
            'label' => $ll . 'item.documents',
            'config' => [
                'readOnly' => 1,
                'type' => 'inline',
                'foreign_table' => 'tx_myext_domain_model_document',
                'foreign_field' => 'item_id',
                'behaviour' => [
                    'enableCascadingDelete' => 1,
                ]
            ],
        ]
    ]
];

tx_myext_domain_model_document子表:


<?php

$ll = 'LLL:EXT:myext/Resources/Private/Language/locallang_db.xlf:';

return [
    'ctrl' => [
        'title' => $ll . 'document',
        'label' => 'item_id',
        'tstamp' => 'updated_at',
        'crdate' => 'created_at',
    ],
    'interface' => [
        'showRecordFieldList' => ''
    ],
    'columns' => [
        'pid' => [
            'label' => $ll . 'pid',
            'config' => [
                'type' => 'passthrough',
            ]
        ],     
        // ...   
        'item_id' => [
            'label' => $ll . 'item.id',
            'config' => [
                'type' => 'input',
                'size' => '10',
                'eval' => 'int',
            ],
        ],
    ],
];

有人知道我做错了什么吗?

提前感谢您的帮助。

【问题讨论】:

    标签: typo3


    【解决方案1】:

    您告诉 TCA 查找关系的字段“item_id”

    'foreign_field' => 'item_id',
    

    但此字段用于项目的 id。 在此字段中,typo3 应该存储来自父元素的 uid。 尝试在 passthrough 上设置“item_id”字段并创建一个新元素并检查数据库是否在该字段中存储了来自父级的 uid。如果是这种情况,那么 cascadeDelete 应该可以工作。 enableCascadingDelete 默认开启:)

    编辑:
    如果您在代码中执行这些操作并使用 extbase 存储库删除需要将 @cascade remove 添加到项目模型中的属性文档的对象。在以下文档中进行了描述:

    https://docs.typo3.org/typo3cms/ExtbaseFluidBook/5-Domain/2-implementing-the-domain-model.html#implementing-relationships-between-domain-objects

    【讨论】:

    • 问题是仅通过代码将文档添加到项目中。我可以看到父表计数器中的 documents 字段行为正确。我不希望它可以通过管理面板进行编辑。
    • 如果您使用 extbase 存储库删除代码中的对象,则需要将 @cascade remove 添加到项目模型中的属性文档中。在文档中描述了她:docs.typo3.org/typo3cms/ExtbaseFluidBook/5-Domain/…
    • 是的!谢谢@Xippo!我错过了@cascade 注释!我不知道我是怎么错过的。请用这个建议更新你的问题,我会接受它:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多