In Doctrine you could set a fetch mode in your entities to fetch all data by one query and not lazy load all of them.
/**
* @ORM\OneToOne(targetEntity="Application\Entity\Categorie" , fetch="EAGER")
* @ORM\JoinColumn(name="CAT_ID", referencedColumnName="CAT_ID")
* @access protected
* @var \Application\Entity\Categorie
*/
protected $CAT_ID;
I have problems with this when it comes to a 3rd level.
Entity "a" has a relation to entity "b". Entity "b" has a relation to entity "c". Entity "a" and entity "b" are selected in one query and entity "c" is separated from them in a single query. I´ve set fetch="EAGER"
on every relation between them.
Doesnt Doctrine handle fetch="EAGER"
in a 3rd level or what is going wrong?
I don't think so, but what you can do is set EAGER mode only when neccessary
<?php
$query = $em->createQuery("SELECT u FROM MyProject\User u");
$query->setFetchMode("MyProject\User", "address", \Doctrine\ORM\Mapping\ClassMetadata::FETCH_EAGER);
$query->execute();
For more information turn to Doctrine docs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With