Summary: Doctrine Embedded types are failing to be populated when they are contained in entities which are themselves contained in another top-level entity.
Details: I have a top-level entity A
which has a ManyToOne
relationship with an intermediate-level entity B
, which in turn has an Embedded object C
.
When I retrieve the top-level entity (using $entityManager->getRepository(A::class)->find($aid)
), the returned A object's $b
variable has its $c
property explicitly set to null (rather than - as you might expect - being absent altogether). Querying the $c
property does not cause B
to hydrate - instead $c remains null.
If I first put a dummy call into to get a simple property of B
e.g. reference
, then B
hydrates correctly and $c
is populated correctly.
Similarly, if I come in at the intermediate level with $entityManager->getRepository(B::class)->find($bid)
then there is no problem either.
Is this a limitation in Doctrine?
(A possible complicating factor is the fact that A itself is a base class for 2 further entities)
/**
* @Entity
* @InheritanceType("SINGLE_TABLE")
* @DiscriminatorColumn(name="type", type="string")
* @DiscriminatorMap({"child1" = "Child1 "child2" = "Child2"})
* @Table(name="A")
*/
class A
{
/**
* @ManyToOne(targetEntity="Model\B", inversedBy="As")
* @JoinColumn(name="b_id", referencedColumnName="id",)
* @var B
*/
public $b;
}
/**
* @Entity
* @Table(name="b")
*/
class B
{
/**
* @Embedded(class="Model\C", columnPrefix = false)
* @var C
*/
public $c;
/**
* @Column(type="string")
* @var string
*/
public $reference;
}
/**
* @Embeddable
*/
class C
{
/**
* @Column(type="smallint")
* @var int
*/
public $type;
}