I am using Symfony with the Doctrine.
To solve the problem, I want:
- or When I extend the Entity class, I want the doctrine to ignore the annotation of the @entity parent class (to see it as @MappedSuperclass)
- or (this is the preferred option). When I extend the Entity class, add something like @MappedChildclass to the child class to know that this class is Entity, but the actual implementation and mappings in the parent class
Let's look at a specific problem:
I have 3 packages:
- AppBridgeBundle
- Userbundle
- Profilebundle
UserBundle and UserProfile should be separated. AppBridgeBundle is a bridge between two packages, it will connect both.
UserBundle has UserEntity :
class UserEntity { private $profileData;
UserBundle has its own ProfileData interface (untied, we only need to implement the implementation of this interface).
ProfileBundle has ProfileEntity :
class ProfileEntity implements Acme\ProfileEntity\Interfaces\Profile {
Profile The bundle has its own interface profile (untethered).
Basically, the ProfileData and profile interfaces are the same.
The AppBridgeBundle now introduces the Adapter of Profile and ProfileData interfaces for customizing the UserBundle using the ProfileBundle.
class ProfileAdapter extends \Acme\ProfileBundle\Entity\ProfileEntity implements \Acme\UserBundle\Interfaces\ProfileData, \Acme\ProfileBundle\Interfaces\Profile { }
Then we add the implementation of the interface to the config.yml application config.yml :
orm: resolve_target_entities: Acme\UserBundle\Interfaces\ProfileData: Acme\AppBridgeBundle\Entity\ProfileAdapter
Now the problem is that when I update the doctrine scheme, it causes an error that Acme\AppBridgeBundle\Entity\ProfileAdapter not an entity.
If I tag ProfileAdapter with @Entity then it will create two separate tables - I don't need it
If I mark the ProfileAdapter using @Entity with the same name as ProfileEntity - @Table('profileentity') , then it gives me an error message table profile already exists
If I flag ProfileEntity with @ORM\MappedSuperclass and remove @Entity annotations from it, I will lose the standard implementation of the ProfileEntity class (so it can no longer work without a bridge).
if I tag ProfileEntity with @InheritanceType("SINGLE_TABLE") , it will add an unnecessary discriminator field to my table in the table.
Any suggestions?