Reputation: 105
I have some different domain-models, each being parent of different sub-models. All of those domain-models extend themselves out of a basic model class and I want to write a general function in the base-model, that deals with subclasses of the current model. Therefore, I need to find a way, to dynamically get all child-model-classes of a given domain-model. Can this be done somehow ? Perhaps via Object-Storage-Definitions or similar ?!
Update : as mentioned in the comment section, mny question had nothing to do with TYPO3, it was a general php-question .. solution for my question are reflection-classes.
Upvotes: 0
Views: 260
Reputation: 4526
You are talking about Database Relationships. Yes, this can be done in TYPO3.
Each model
should be mapped to a table
. So, let's take for example the Category
domain model and parent
property
class Category extends AbstractEntity
{
/**
* @var \TYPO3\CMS\Extbase\Domain\Model\Category
*/
protected $parent = null;
/**
* @return \TYPO3\CMS\Extbase\Domain\Model\Category
*/
public function getParent()
{
if ($this->parent instanceof \TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy) {
$this->parent->_loadRealInstance();
}
return $this->parent;
}
/**
* @param \TYPO3\CMS\Extbase\Domain\Model\Category $parent
*/
public function setParent(\TYPO3\CMS\Extbase\Domain\Model\Category $parent)
{
$this->parent = $parent;
}
The parent property will return the parent category. The same logic is when you want to get the childs.
Upvotes: 1