0

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.

Oliver
  • 105
  • 13
  • Since my question was not described well I will try to make it more clear : Is it possible, to check all properties of an initialized typo3-domain-model-object if they are of type object-storage and if so, return specific info about that related child model type (tablename, classname and so on) – Oliver Dec 19 '17 at 11:31

2 Answers2

1

I guess your question has nothing to do with TYPO3, so take a look at this general PHP question thread and possible solutions here.

Wolfgang
  • 593
  • 3
  • 8
  • Indeed your link made me read about reflection-classes, which is exactly what I was looking for. Thanks – Oliver Dec 19 '17 at 11:34
1

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.

Andrei Todorut
  • 4,260
  • 2
  • 17
  • 28
  • Yes, I am aware of that. My question (sorry if it was not described well) was, if it is possible, to check all properties of an initialized typo3-domain-model-object if they are of type object-storage and if so, return specific info about that related child model type (tablename, classname and so on) !? – Oliver Dec 19 '17 at 11:29