Symfony2 map entity to different tables
Do you absolutely need your $baz attribute ? and how do you determine it?
Because a simple solution that might help you is to make an abstract foo class, and then 2 classes that inherit from it and that do the database's relation.
Here is the example :
abstract class foo { /** * @ORM\Column(name="id", type="integer") * @ORM\Id */ protected $id; /** * @ORM\Column(name="bar", type="string") */ protected $bar;}/* @ORM\Table(name="foo1")* @ORM\Entity(repositoryClass="yourRepo")*/foo1 extends foo{}/* @ORM\Table(name="foo2")* @ORM\Entity(repositoryClass="yourRepo")*/foo2 extends foo{}
Though I'm not sure it works as simply as this but maybe it could help.
Some documentation that might help doing this : http://docs.doctrine-project.org/en/2.0.x/reference/inheritance-mapping.html
Please feel free to edit/correct, I'm pretty new in this but I think the idea might help .