Question: How do you load an object with an associated object that uses inheritance mapping with doctrine?
For example using these objects: (ignore typos I renamed things from my real example code)
/**
* @ORM\Table(name="int_entity")
* @ORM\Entity
* })
*/
class IntEntity extends BaseEntity
{
/**
* @ORM\Column(name="int_value", type="integer", nullable=true)
**/
public $intValue;
}
/**
* @ORM\Table(name="float_entity")
* @ORM\Entity
* })
*/
class floatEntity extends FakeBaseMixedEntity
{
/**
* @ORM\Column(name="float_value", type="float", nullable=true)
**/
public $floatValue;
}
/** @ORM\MappedSuperclass */
class BaseEntity
{
/**
* @ORM\Column(name="id", type="integer")
* @ORM\Id
*/
private $id;
//could be other variables I guess but I didn't need any. The point of the
//base class in my case is more of an interface I guess...
}
/**
* @ORM\Table(name="Entity_Containing_Inherited_Entity")
* @ORM\Entity
* })
*/
class EntityContainingInheritedEntity
{
/**
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
public $id;
/**
* @ORM\Column(name="string_value", type="string")
*/
public $stringValue;
/**
* @ORM\OneToOne(targetEntity="BaseEntity", cascade={"persist"})
* @ORM\JoinColumn(name="id", referencedColumnName="id")
**/
public $mixedEntity;
}
loading doesn't work
$em = $this->getDoctrine()->getManager();
$loadedValue = $em->getRepository('BundleName:EntityContainingInheritedEntity')->findAll();
however saving does
public function indexAction(Request $request)
{
$floatE = new floatEntity();
$floatE->floatValue = 1.01;
$floatE->setId(rand());
$floatEContainer = new EntityContainingInheritedEntity();
$floatEContainer->stringValue = 'hello';
$floatEContainer->mixedEntity = $floatE;
$intE = new intEntity();
$intE->intValue = 100;
$intE->setId(rand());
$intEContainer = new EntityContainingInheritedEntity();
$intEContainer->stringValue = 'hello';
$intEContainer->mixedEntity = $intE;
$em = $this->getDoctrine()->getManager();
$em->persist($floatEContainer);
$em->persist($intEContainer );
$em->flush();
}
When loading it says the proxy doesn't exist. So I searched that and first off doctrine isn't supposed to even try making a proxy when there is inheritance mapping like this (at least that is how I interpreted the docs http://docs.doctrine-project.org/en/2.0.x/reference/inheritance-mapping.html#performance-impact
I have cleared my cache a nothing changed.
I have tried to add eager loading to annotation nothing changed.
I also kind of got the gist from my search I was supposed to use DQL instead of findAll() the below has the same proxy cache error message
$query = $em->createQuery("SELECT u FROM Path\To\Entity\EntityContainingInheritedEntity u");
$users = $query->getResult();
Mentioned error message: ContextErrorException: Warning: require( /path/app/cache/dev/doctrine/orm/Proxies/__CG__BundleNameEntityBaseEntity.php): failed to open stream: No such file or directory in /path/vendor/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyFactory.php
BTW this doesn't solve my problem: Doctrine 2 Inheritance Mapping with Association