I'm using Symfony with Doctrine.
To resolve my problem I want to:
- or When I'm extending Entity class I want the doctrine to ignore parent's class @entity annotation (to see it as @MappedSuperclass)
- or (this one is more preferable) When I'm extending Entity class add to child class something like @MappedChildclass just to know that this class is an Entity, but actual implementation and mappings in the parent class
Lets see concrete problem:
I have 3 bundles:
- AppBridgeBundle
- UserBundle
- ProfileBundle
UserBundle and UserProfile must be decoupled. AppBridgeBundle is a bridge between 2 bundles, it will couple both.
UserBundle has UserEntity:
/**
* @ORM\Entity
**/
class UserEntity {
/**
* @var \Acme\UserBundle\Interfaces\ProfileData
* @ORM\ManyToOne(targetEntity="Acme\UserBundle\Interfaces\ProfileData",
cascade={"persist"})
* )
*/
private $profileData;
// ...
}
UserBundle has its own interface ProfileData (decoupled, we only need to inject implementation of this interface).
ProfileBundle has ProfileEntity:
/**
* @ORM\Entity
**/
class ProfileEntity implements Acme\ProfileEntity\Interfaces\Profile {
// properties ...
}
ProfileBundle has its own interface Profile (decoupled).
Basically ProfileData and Profile interfaces are the same.
Now AppBridgeBundle introduces Adapter of Profile and ProfileData interfaces to adapt UserBundle with ProfileBundle.
class ProfileAdapter extends \Acme\ProfileBundle\Entity\ProfileEntity
implements \Acme\UserBundle\Interfaces\ProfileData,
\Acme\ProfileBundle\Interfaces\Profile {
}
Next, we inject our interface implementation in the config.yml
app configuration:
orm:
resolve_target_entities:
Acme\UserBundle\Interfaces\ProfileData: Acme\AppBridgeBundle\Entity\ProfileAdapter
Now, the problem is that when I update doctrine schema it throws me an error that Acme\AppBridgeBundle\Entity\ProfileAdapter
is not Entity.
If I mark ProfileAdapter with
@Entity
then it will create 2 separate tables - I don't need itIf I mark ProfileAdapter with
@Entity
with the same name as ProfileEntity -@Table('profileentity')
then it throws me an error thattable profile already exists
If I mark ProfileEntity with
@ORM\MappedSuperclass
andremove @Entity
annotation from it - I'll loose default implementation of the ProfileEntity class (so it cant work without bridge anymore).if I mark ProfileEntity with
@InheritanceType("SINGLE_TABLE")
it will add to the tables unnecessary discriminator field to my table.
Any suggestions?