Jochen Fröhlich
2018-03-21 14:30:01 UTC
Hi there,
I'm trying to query a repository to retrieve objects representing subclasses that were defined via Single Table Inheritance.
See docs.typo3.org/typo3cms/ExtbaseFluidBook/6-Persistence/5-modeling-the-class-hierarchy.html
It's quite the same problem as described here: forum.typo3.org/index.php?t=msg&goto=736175
What works:
To distinguish the various subclasses I defined a field record_type.
In the backend form, the RecordType can be selected.
The fields are changing according to the definitions for the various subclasses.
The correct RecordType is stored in the DB field record_type.
What doesn't work:
When I try to retrieve objects of the subclasses in the controller, only objects of type BaseClass (which each SubClass extends) are returned.
Below you find my current configuration. TYPO3 / Extbase 8.7.11.
What am I missing? Please let me know if you need any more details.
Thanks in advance for any hints.
Cheers,
Jochen
###################
Directory structure:
[ExtName]
-- [Classes]
---- [Domain]
------ [Model]
-------- BaseClass.php
-------- [Base]
---------- SubClassA.php
---------- SubClassB.php
------ [Repository]
-------- BaseClassRepository.php
###################
TypoScript-Setup of EXT:ExtName:
config.tx_extbase.persistence.classes {
\VendorName\ExtName\Domain\Model\BaseClass {
mapping {
tableName = tx_extname_domain_model_baseclass
recordType = \VendorName\ExtName\Domain\Model\BaseClass
}
subclasses {
\VendorName\ExtName\Domain\Model\Base\SubClassA = \VendorName\ExtName\Domain\Model\Base\SubClassA
\VendorName\ExtName\Domain\Model\Base\SubClassB = \VendorName\ExtName\Domain\Model\Base\SubClassB
}
}
\VendorName\ExtName\Domain\Model\SubClassA {
mapping {
tableName = tx_extname_domain_model_baseclass
recordType = \VendorName\ExtName\Domain\Model\SubClassA
}
}
\VendorName\ExtName\Domain\Model\SubClassB {
mapping {
tableName = tx_extname_domain_model_baseclass
recordType = \VendorName\ExtName\Domain\Model\SubClassB
}
}
}
plugin.tx_extname_extname {
view { ... }
settings { ... }
}
###################
TCA for tx_extname_domain_model_baseclass:
'types' => [
'\VendorName\ExtName\Domain\Model\Base\SubClassA' => [
'showitem' => 'record_type, name, ...'
],
'\VendorName\ExtName\Domain\Model\Base\SubClassB' => [
'showitem' => 'record_type, name, ...'
],
]
###################
SubClassA:
namespace VendorName\ExtName\Domain\Model\Base;
use VendorName\ExtName\Domain\Model\BaseClass;
class SubClassA extends BaseClass { ... }
###################
BaseClassController.php: (retrieves only objects of type BaseClass)
public function listAction() {
$records = $this->baseClassRepository->findAll();
$this->view->assign('records', $records);
}
###################
I'm trying to query a repository to retrieve objects representing subclasses that were defined via Single Table Inheritance.
See docs.typo3.org/typo3cms/ExtbaseFluidBook/6-Persistence/5-modeling-the-class-hierarchy.html
It's quite the same problem as described here: forum.typo3.org/index.php?t=msg&goto=736175
What works:
To distinguish the various subclasses I defined a field record_type.
In the backend form, the RecordType can be selected.
The fields are changing according to the definitions for the various subclasses.
The correct RecordType is stored in the DB field record_type.
What doesn't work:
When I try to retrieve objects of the subclasses in the controller, only objects of type BaseClass (which each SubClass extends) are returned.
Below you find my current configuration. TYPO3 / Extbase 8.7.11.
What am I missing? Please let me know if you need any more details.
Thanks in advance for any hints.
Cheers,
Jochen
###################
Directory structure:
[ExtName]
-- [Classes]
---- [Domain]
------ [Model]
-------- BaseClass.php
-------- [Base]
---------- SubClassA.php
---------- SubClassB.php
------ [Repository]
-------- BaseClassRepository.php
###################
TypoScript-Setup of EXT:ExtName:
config.tx_extbase.persistence.classes {
\VendorName\ExtName\Domain\Model\BaseClass {
mapping {
tableName = tx_extname_domain_model_baseclass
recordType = \VendorName\ExtName\Domain\Model\BaseClass
}
subclasses {
\VendorName\ExtName\Domain\Model\Base\SubClassA = \VendorName\ExtName\Domain\Model\Base\SubClassA
\VendorName\ExtName\Domain\Model\Base\SubClassB = \VendorName\ExtName\Domain\Model\Base\SubClassB
}
}
\VendorName\ExtName\Domain\Model\SubClassA {
mapping {
tableName = tx_extname_domain_model_baseclass
recordType = \VendorName\ExtName\Domain\Model\SubClassA
}
}
\VendorName\ExtName\Domain\Model\SubClassB {
mapping {
tableName = tx_extname_domain_model_baseclass
recordType = \VendorName\ExtName\Domain\Model\SubClassB
}
}
}
plugin.tx_extname_extname {
view { ... }
settings { ... }
}
###################
TCA for tx_extname_domain_model_baseclass:
'types' => [
'\VendorName\ExtName\Domain\Model\Base\SubClassA' => [
'showitem' => 'record_type, name, ...'
],
'\VendorName\ExtName\Domain\Model\Base\SubClassB' => [
'showitem' => 'record_type, name, ...'
],
]
###################
SubClassA:
namespace VendorName\ExtName\Domain\Model\Base;
use VendorName\ExtName\Domain\Model\BaseClass;
class SubClassA extends BaseClass { ... }
###################
BaseClassController.php: (retrieves only objects of type BaseClass)
public function listAction() {
$records = $this->baseClassRepository->findAll();
$this->view->assign('records', $records);
}
###################