Simple Object Inheritance in FLOW3
Think about two objects. One of them we want to call Income and the other one Spending. Both of them share the very same properties:
- They have an
amount
- They are based on a
currency
- Probably they also have a
date
Base
class where both can inherit from.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
/** * A Base * @FLOW3\Entity * @ORM\MappedSuperclass */ abstract class Base { /** * The name * @var string */ protected $name; /** * The currency * @var \MG\App\Domain\Model\Currency * @ORM\ManyToOne */ protected $currency; /** * The amount * @var float */ protected $amount; /** * Date * @var \DateTime */ protected $date; } |
The classes which inherit from this base class now look very simple:
1 2 3 4 5 6 7 8 |
/** * An Income * * @FLOW3\Entity */ class Income extends \MG\App\Domain\Model\Base { } |
The keyword in this whole thing is the annotation in the base class:
1 |
@ORM\MappedSuperclass |
With that Doctrine creates only the income and spendings tables but NOT a table like ‘base’. This sounds pretty obvious but if you don’t know about this annotation it can drive you mad …
UPDATE: Please note that every mention of FLOW3 changed to Flow since the release of TYPO3 Flow version 2.
Thanks, man. That really almost drove me crazy, until I found this…