Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Doctrine 2 fetch="EAGER"

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?

like image 322
Stillmatic1985 Avatar asked Sep 20 '13 15:09

Stillmatic1985


1 Answers

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.

like image 140
akond Avatar answered Sep 30 '22 19:09

akond