I'm not sure if this is possible:
I have deep relations between several entities, and I don't know how to efficiently count the related entities, to show the cumulative totals for each one.
- I have a "Magazine".
- A "Magazine" have several "Issues".
- An "Issue" have several "Chapters".
- A "Chapter" have several "Pages".
- And so on...
I want to display something like:
Magazine A: 6 issues, 12 chapters, 24 pages
Magazine B: 12 issues, 20 chapters, 51 pages
So, when retrieving a "Magazine":
$entities = $em->getRepository('MyBundle:Magazine')->findBy(array(),
array('name' => 'ASC'));
In the template I can do this:
<td>{{ entity.issues.count }}</td>
To show the number of "Issues" related to that "Magazine".
My problem is that now I want the cumulative number of "Chapters" that these subset of "Issues" have, and so on. Something like:
<td class="counter">{{ entity.issues.chapters.count }}</td>
<td class="counter">{{ entity.issues.chapters.pages.count }}</td>
Obviously this doesn't work, and I can't figure out a way to do this. Is there a way to do this?