phpormdoctrine

Doctrine: extending entity class


I would like to extend Entity\Base classes, how to do this in Doctrine 2.1? My research showed that whenever someone encounters the problem with doing this he switches to Doctrine 1.2 :)n I am using yaml configuration


Solution

  • Doctrine 2.X Entities work as POPOs (Plain Old PHP Objects). To achieve extending correctly, Doctrine enforces you to use a concept from JPA called Mapped Super Classes. The idea is pretty simple. Whenever you want to have a base class and want your entities to extend from it (I'm not talking about inheritance at DB level), all you need to do is create your Base class as a MappedSuperClass.

    Here is an example: https://www.doctrine-project.org/projects/doctrine-orm/en/latest/reference/inheritance-mapping.html#mapped-superclasses

    Thanks