I didn't find informations about that.
A lot of peoples tell me that is a non-sense to put @Entity annotation on an abstract class. From my point of view when I make a PHP abstract class I mainly expect no PHP code can create instances using new operator.
Some peoples tell me to use @MappedSuperClass on classes like ChildrenAbstract but unless I remove @Entity annotation that seems useless because I sometime need mappings that are not allowed with @MappedSuperClass.
A lot of peoples asks me why so here is basically why :
ParentAbstract.php
/**
* @ORM\Table(name="ParentAbstract")
* @ORM\Entity(repositoryClass="App\Repository\ParentAbstractRepository")
* @ORM\InheritanceType("JOINED")
* @ORM\DiscriminatorColumn(name="discr", type="string")
* @ORM\DiscriminatorMap({"childrenAbstract" = "ChildrenAbstract", "concreteA" = "ConcreteA", "concreteB" = "ConcreteB"})
*/
abstract class ParentAbstract
{
...
}
ChildrenAbstract.php
/**
* @ORM\Table(name="ChildrenAbstract")
* @ORM\Entity(repositoryClass="App\Repository\ChildrenAbstractRepository")
*/
abstract class ChildrenAbstract extends ParentAbstract
{
/** * @ORM\Column(type="string", nullable=true) */
private $picture;
}
ConcreteA.php
/**
* @ORM\Table(name="ConcreteA")
* @ORM\Entity(repositoryClass="App\Repository\ConcreteARepository")
*/
class ConcreteA extends ChildrenAbstract
{
...
}
ConcreteB.php
/**
* @ORM\Table(name="ConcreteB")
* @ORM\Entity(repositoryClass="App\Repository\ConcreteBRepository")
*/
class ConcreteB extends ChildrenAbstract
{
...
}
ChildrenAbstractController.php
class ChildrenAbstractController extends AbstractController
{
/**
* @Route("/home/childrenabstract/get/picture/{id}", name="get_childrenabstract_picture")
*/
public function getChildrenAbstractPicture(Request $request, int $id) : Response
{
$childrenAbstract = $this->getDoctrine()->getRepository(ChildrenAbstract::class)->findById($id);
if(!$childrenAbstract)
{
throw new \Exception("childrenAbstract don't exists !");
}
$response = new BinaryFileResponse("../path/".$childrenAbstract->getId()."/".$childrenAbstract->getPicture());
$response->headers->set('Content-Type', 'image/' . 'png');
$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_INLINE);
return $response;
}
ConcreteAFront.html.twig
{% for concreteA in container.concreteAs %}
<td>{{ form_label(form.picture) }}</td><td><img src="{{ path('get_childrenabstract_picture', {id:concreteA.id}) }}" /></td>
{% endfor %}
ConcreteBFront.html.twig
{% for concreteB in container.concreteBs %}
<td>{{ form_label(form.picture) }}</td><td><img src="{{ path('get_childrenabstract_picture', {id:concreteB.id}) }}" /></td>
{% endfor %}
I need a "generic" route to interact with some part of concrete structure and sometime mappings in AbctractChildren.php are more complex with @ORM\ManyToOne, @ORM\ManyToMany, ...
The point is that is perfectly working. Or that seems to perfelctly works. I need to be sure Doctrine2 is designed to support that way or if it's a bad practice to avoid.