File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,10 @@ Thanks for contributions to:
2222- ** [ everzet] ( http://github.com/everzet ) Kudryashov Konstantin** for TreeLevel implementation
2323- ** [ stof] ( http://github.com/stof ) Christophe Coevoet** for getTreeLeafs function
2424
25+ Update ** 2017-04-22**
26+
27+ - Added the ` TreeObjectHydrator ` class for building trees from entities
28+
2529Update ** 2012-06-28**
2630
2731- Added "buildTree" functionality support for Closure and Materialized Path strategies
@@ -636,6 +640,31 @@ $controller = $this;
636640
637641<a name =" advanced-examples " ></a >
638642
643+ ## Building trees from your entities
644+
645+ You can use the ` childrenHierarchy ` method to build an array tree from your result set.
646+ However, sometimes it is more convenient to work with the entities directly. The ` TreeObjectHydrator `
647+ lets you build a tree from your entities instead, without triggering any more queries.
648+
649+ First, you have to register the hydrator in your Doctrine entity manager.
650+
651+ ``` php
652+ <?php
653+ $em->getConfiguration()->addCustomHydrationMode('tree', 'Gedmo\Tree\Hydrator\ORM\TreeObjectHydrator');
654+ ```
655+
656+ The hydrator requires the ` HINT_INCLUDE_META_COLUMNS ` query hint. Without it the hydrator will not work!
657+ Other than that, the usage is straight-forward.
658+
659+ ``` php
660+ <?php
661+ $repo = $em->getRepository('Entity\Category');
662+
663+ $tree = $repo->createQueryBuilder('node')->getQuery()
664+ ->setHint(\Doctrine\ORM\Query::HINT_INCLUDE_META_COLUMNS, true)
665+ ->getResult('tree');
666+ ```
667+
639668## Advanced examples:
640669
641670### Nesting Translatable and Sluggable extensions
You can’t perform that action at this time.
0 commit comments