Created
December 30, 2011 14:25
-
-
Save juzna/1540088 to your computer and use it in GitHub Desktop.
Doctrine partial fetch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// method 1 - partial fetch | |
{ | |
$q = $em->createQuery("select partial a.{id,title}, length(a.body) from Model\\Article a"); | |
$q->setMaxResults(1); | |
$list = $q->execute(); | |
$entity = $list[0][0]; | |
/*dump($entity);*/ | |
var_dump($entity->body); // NULL as it was not fetched | |
$id = $entity->id; | |
unset($entity); | |
} | |
// method 2 - normal fetch | |
{ | |
$entity2 = $this->getRepository(\Model\Article::getClassName())->find($id); | |
var_dump($entity2->body); // NULL wtf?? | |
// Cause: it already exists in IdentityMap and is not fetched again | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment