首页 > 解决方案 > Typo3 9.5 子类和外部表

问题描述

在 Typo3 9.5 中使用单表继承时,如何为子类中定义的属性指定外部表?

我在 ext_typoscript_setup.txt 中定义了类继承:

config.tx_extbase.persistance.classes {
    MyProject\Base { mapping {
       tablename = tx_myproject_base
       subclasses = {
          1 = MyProject\Derived
       }
    }}
    MyProject\Derived { mapping {
       tablename = tx_myproject_base
       recordType = 1
       columns = {
           choice.mapOnProperty = selection
       }
    }}
    MyProject\Choice { mapping {
       tablename = tx_myproject_choice
   }}
}

在 Configuration/TCA/tx_myproject_base.php 中,我有

return [
  'ctrl' => ['type' => 'subclass'],
  'columns' => [
     // some fields of the base type
     // and now the fields of the derived type
     'choice' => [
         'config' => [
           'type' => 'select',
           'foreign_table' => tx_myproject_choice,
           'size' => 1,
           'minitems' => 0, 'maxitems' => 1,
           'renderType' => 'selectSingle',
         ]
  ]]
];

所以派生对象有一个外键进入选择,在数据库中称为选择,在 php 中称为选择。

当我在控制器中执行 setOrderings('selection.ranking'=>DESCENDING) 时,出现错误

The relation information for property "selection" of class "MyProject\Derived" is missing.

在调试输出中,我看到该字段已正确映射到选择字段,但缺少 foreign_table 信息。

我假设问题是我在基表的 PHP 文件中有子类的 TCA 配置,但我不知道如何解决这个问题。

如何让 Extbase 理解子类型的字段是外来模型的关键?

标签: typo3extbasetypo3-9.x

解决方案


推荐阅读