Skip to content

Instantly share code, notes, and snippets.

@juzna
Created December 30, 2011 14:25
Show Gist options
  • Save juzna/1540088 to your computer and use it in GitHub Desktop.
Save juzna/1540088 to your computer and use it in GitHub Desktop.
Doctrine partial fetch
<?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