I have an entity A which has a OneToOne relationship with entity B which has a ManyToOne relationship to entity C.
A 1:1 B 1:n C
If I load A the connected B is fetched, but C is still null although I defined C in B as fetch="EAGER"
Is this the correct behaviour? Can I get C by fetching A with a findAll statement?
Here is my code: in class A "Charge":
/**
* One Charge has one ChargeDetail.
*
* @ORM\OneToOne(targetEntity="ChargeDetail", inversedBy="charge", cascade={"persist"})
* @ORM\JoinColumn(name="charge_detail_id", referencedColumnName="id")
*/
private ?ChargeDetail $chargeDetail = null;
in class B ChargeDetail:
/**
* @ORM\ManyToOne(targetEntity="Fraud", fetch="EAGER")
* @ORM\JoinColumn(name="fraud_id", referencedColumnName="id")
*/
private ?Fraud $fraud = null;
Class C Fraud
/**
* @ORM\Entity(repositoryClass="App\Repository\FraudRepository")
* @codeCoverageIgnore
*/
class Fraud
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="smallint", options={"unsigned":true})
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private ?int $id = null;
/**
* @ORM\Column(type="string", length=255)
*/
private string $name;
.....
In the code:
/* @var Charge[] $charges */
$charges = $this->chargeRepo
->findBy([], ['id' => 'DESC'], 1, 0);
$charge = $charges[0];
$charge will have the property chargeDetail filled correctly, but chargeDetail will still have fraud as null.