Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Doctrine 2 nested set - retrieve full tree in single query

I'm using stof/StofDoctrineExtensionsBundle (Bundle wrapper for Atlantic18/DoctrineExtensions) to implement a Nested Set (tree) entity. The entity is configured and working, but I can't figure out how to retrieve all root notes with all of their children (full trees) in a single query. I currently have the full collection returning however it lazy loads all children, meaning a large number of queries is performed.

Thanks for any help.

like image 869
James Crinkley Avatar asked Jul 02 '16 22:07

James Crinkley


1 Answers

You can just use childrenHierarchy() method for whole tree retrieve:

$tree = $repo->childrenHierarchy();  
like image 143
vp_arth Avatar answered Sep 22 '22 07:09

vp_arth