Skip to content

Instantly share code, notes, and snippets.

@cakper
Created December 8, 2011 07:29
Show Gist options
  • Save cakper/1446386 to your computer and use it in GitHub Desktop.
Save cakper/1446386 to your computer and use it in GitHub Desktop.
Doctrine not working eager loading
<?php
$query = $em->createQuery('SELECT t FROM JazzyTransactionBundle:MoneyTransaction t WHERE t.sender = :user')->setParameter('user', $user);
$query->setFetchMode("JazzyTransactionBundle:MoneyTransaction", "sender", "EAGER");
$transactions = $query->execute();
WORKING:
<?php
$query = $em->createQuery('SELECT t FROM JazzyTransactionBundle:MoneyTransaction t WHERE t.sender = :user')->setParameter('user', $user);
$query->setFetchMode("Jazzy\TransactionBundle\Entity\MoneyTransaction", "sender", \Doctrine\ORM\Mapping\ClassMetadata::FETCH_EAGER);
$transactions = $query->execute();
@frickenate
Copy link

Yeah, even 3 years later I came across this same issue. setFetchMode() apparently requires a fully classified class name (FQCN) and not an alias shortcut - similar to the targetEntity attribute of association configuration.

Frankly I don't know why they bothered adding aliases for namespaces if you can't use them in half the places Doctrine expects a class name.

@vetalt
Copy link

vetalt commented Oct 13, 2015

"EAGER" is not same as \Doctrine\ORM\Mapping\ClassMetadata::FETCH_EAGER

@kafoso
Copy link

kafoso commented Apr 18, 2018

@vetalt: Thank you, Sir! This trolled me for a littel while.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment