Created
October 22, 2013 14:05
-
-
Save sglessard/7101357 to your computer and use it in GitHub Desktop.
SGLFLTS - Doctrine2 cascade example to fetch all entities
This file contains hidden or 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
| // Init Method | |
| $query = $this->createQueryBuilder('b') | |
| ->select('b') | |
| ->orderBy('b.number', 'DESC'); | |
| // WRONG Query | |
| // Was feching task's works with additional SQL Queries (task's works loop in twig tmpl) | |
| $query = $this->retrieve(true) | |
| ->select('b,p,t,w') | |
| ->innerjoin('b.part','p') | |
| ->innerjoin('p.tasks','t') | |
| ->innerjoin('b.works','w') | |
| ->where('b = :id_bill') | |
| ->setParameter('id_bill', $id_bill); | |
| // GOOD Query | |
| // Now does 1 SQL Query for all fetched entities | |
| $query = $this->retrieve(true) | |
| ->select('b,p,t,w') | |
| ->innerjoin('b.part','p') | |
| ->innerjoin('p.tasks','t') | |
| ->innerjoin('t.works','w') | |
| ->where('w.bill = :id_bill') | |
| ->setParameter('id_bill', $id_bill); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment