I have a PHP entity that inherits from a base class contained in a library which I cannot change. I would like to map properties that are inherited from the base class to database columns. Since the @Column
annotation must be used on a field of method, I can not define the inherited columns that way. Using @AttributeOverrides
also will not work as then I would need to have access to the base class to make it a MappedSuperclass.
Example of classes:
class LibraryClass
{
protected $someProperty;
}
/**
* @Entity
* @Table(name="child")
*/
class Child extends LibraryClass
{
/**
* @Column(name="some_property", type="string")
* Somehow target $this->someProperty
*/
}
Is there any other way to map parent properties without transferring the properties between classes and not using inheritance?
You could use mapping with XML or YML instead of annotations. It's documented here.
https://symfony.com/doc/current/doctrine.html#add-mapping-information