[TYPO3-mvc] relation to the same table

Bernd Wilke t3n at pi-phi.de
Tue Dec 15 09:36:33 CET 2015


Am 14.12.2015 um 14:09 schrieb Bernd Wilke:
> I have a question about the correct declaration and programming of a
> self-relation of records:
>
>
> I have records of type mydata and there are two special fields: is_alias
> and alias_of (so, as I could not access the values in the
> fluid-templates, I renamed them to isalias and aliasof (without
> underscore))
>
> while is_alias is just a boolean alias_of holds a value of another
> mydata-record.
>
> now I want to get the data of that record (automagically?) and replace
> some fields of the current record with the data of that record.
>
> what would be the best solution?  (I'm using TYPO3 7.6.0)

with help from slack (thanks @kraftb):

in the model:

namespace ME\MyExt\Domain\Model;

class Mydata extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {
	:
	/**
	 * alias of
	 *
	 * @var ME\MyExt\Domain\Model\Mydata|NULL
	 * @lazy
	 * @cascade remove
	 */
	protected $aliasof = 0;
	:

     /**
     * Gets the alias record.
     *
     * @return Mydata|NULL the alias record
     * @api
     */
     public function getAliasof()
     {
         if ($this->aliasof instanceof 
\TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy) {
             $this->aliasof->_loadRealInstance();
         }
         return $this->aliasof;
     }

     /**
      * Sets the alias.
      *
      * @param ME\MyExt\Domain\Model\Mydata $aliasof the alias record
      * @return void
      * @api
      */
     public function setAliasof(Mydata $aliasof)
     {
         $this->aliasof = $aliasof;
     }

     :

     /**
      * Returns the anotation, in case of alias the anotation of master
      *
      * @return string $anotation
      */
     public function getAnotation() {
         if ($this->isalias) return $this->aliasof->getAnotation();
	return $this->anotation;
     }
     :
}


Bernd


More information about the TYPO3-project-typo3v4mvc mailing list