I'm having trouble deciding what kind of Doctrine inheritance is right for my project.
The goal is for a Virtual Machine (VM) to have multiple softwares (PHP, MySQL and so on ...).
Each of these softwares have a distinct class, and some fields in common. I first tried putting in the VM class a relation to each software class, and it worked beautifuly :
/**
* Class VM
*/
class VM
{
/**
* @var \AppBundle\Entity\MySQL
*
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\MySQL", cascade={"persist"})
*
*/
private $mysql;
/**
* @var \AppBundle\Entity\PHP
*
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\PHP", cascade={"persist"})
*
*/
private $php;
...
and other softwares, always the same
}
But now I want to use an abstract class 'Software', from which all my software will inherit, and have in my VM class only a $software attribute. This way it will be easier in the future to add a new software class, inheriting from Software.
My abstract class 'Software' linked to a Virtual Machine (VM) class:
/**
* Class Software
*/
abstract class Software {
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="version", type="string", length=255, nullable=true)
*/
private $version;
/**
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\VM")
*/
private $VM;
}
I tried to put a @ORM\SuperMappedClass
annotation on my Software class, but then I didn't find a way to access children classes. Is this the best doctrine inheritance for this particular case ? Would concrete table inheritance be a better choice ? I don't even know if concrete inheritance is possible since it is not detailed in the doc.