Skip to content

Instantly share code, notes, and snippets.

@afurculita
Created June 26, 2017 19:27
Show Gist options
  • Save afurculita/d4e06ccbfadfcf95bd21cd9b25c73746 to your computer and use it in GitHub Desktop.
Save afurculita/d4e06ccbfadfcf95bd21cd9b25c73746 to your computer and use it in GitHub Desktop.
<?php
//$em is the entity manager
$qb = $em->createQueryBuilder();
// Wasteful, will select all the properties (columns) for the entity
$qb
->select('Article')
->from('Entity\Article')
;
// Better, but won't provide a structure representing our object graph (returns a flat array)
$qb
->select('Article.title')
->from('Entity\Article')
;
// Best (although fragile if trying to manipulate/persist objects later)
$qb
->select('partial Article.{title}')
->from('Entity\Article')
;
// You can select multiple properties in the partial statement
$qb
->select('partial Article.{id,title,summary}')
->from('Entity\Article')
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment