Skip to content

Instantly share code, notes, and snippets.

@sglessard
Created October 22, 2013 14:05
Show Gist options
  • Save sglessard/7101357 to your computer and use it in GitHub Desktop.
Save sglessard/7101357 to your computer and use it in GitHub Desktop.
SGLFLTS - Doctrine2 cascade example to fetch all entities
// 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