I have the following database structure (simplified). All relations are many to one.
table parent:
ID | SOME_DATA
-------------------------------
1 | Lorum
2 | Ipsum
..etc
table child:
ID | PARENT_ID | SOME_DATA
-------------------------------
1 | 2 | Dolor
2 | 5 | Sis
..etc
Using the normal doctrine method to display them all on a single page:
<?php
//get parents
$parents = $this->getDoctrine()->getRepository('FamilyBundle:Parent')->findAll();
//loop through parents
foreach($parents AS $parent){
//display parent
echo '<h1>'.$parent->getName().'</h1>';
//show children
foreach($parent->getChildren() AS $child)
echo '<h2>'.$child->getName().'</h2>';
}
When using the debut tool, I was surprised to find out that in order to retrieve the child entities, a new database query is used for every parent entity. Resulting in a very inefficient script.
Above example is simplified. I could use a raw query if I weren't dependend on some specialised methods in the entity class. So my question is, is there a way to do a smarter query, but still be able to manage the data with the doctrine entity manager so that I can still access the entity class methods. Preferably, I would like to specify which children of the parent entity are preloaded, as I won't need to use all of them.
Anyone can point me in the right direction?