Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. <?php
  2. //$em is the entity manager
  3. $qb = $em->createQueryBuilder();
  4. // Wasteful, will select all the properties (columns) for the entity
  5. $qb
  6. ->select('Article')
  7. ->from('Entity\Article')
  8. ;
  9. // Better, but won't provide a structure representing our object graph (returns a flat array)
  10. $qb
  11. ->select('Article.title')
  12. ->from('Entity\Article')
  13. ;
  14. // Best (although fragile if trying to manipulate/persist objects later)
  15. $qb
  16. ->select('partial Article.{title}')
  17. ->from('Entity\Article')
  18. ;
  19. // You can select multiple properties in the partial statement
  20. $qb
  21. ->select('partial Article.{id,title,summary}')
  22. ->from('Entity\Article')
  23. ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement