Created
June 26, 2017 19:27
-
-
Save afurculita/d4e06ccbfadfcf95bd21cd9b25c73746 to your computer and use it in GitHub Desktop.
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 | |
//$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