You should probably look into nested sets: http://en.wikipedia.org/wiki/Nested_set_model
The extension for Doctrine2 is provided by the DoctrineExtensions library: https://github.com/Atlantic18/DoctrineExtensions/blob/b1c364389992c248fcf50d6793e2fe4042021682/doc/tree.md Marco Pivetta http://twitter.com/Ocramius http://ocramius.github.com/ On 3 December 2014 at 17:39, Javier Garcia <[email protected]> wrote: > Hi, > > I have three models: `Category`, `Product` (references `Category` and > `Brand`) and `Brand`. `Category` is self referencing. I would like to fetch > the name brands associated to each category in **hierarchical way** Any > help? > > This is my try, but it returns zero results:` > > $repository = $this->getDoctrine()->getRepository( > 'ProjectBackendBundle:Subitem'); > $items = $repository->findAll(); > > $qb1 = $repository->createQueryBuilder('s') > ->select('i', 'c', 'b', 's') > ->leftJoin('s.item', 'i') > ->leftJoin('i.children', 'c') > ->where('i.parent IS NULL') > ->leftJoin('ProjectBackendBundle:Brand', 'b', 'WITH', 'b.id = > s.brand') > ->getQuery(); > > > -- > You received this message because you are subscribed to the Google Groups > "doctrine-user" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/doctrine-user. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "doctrine-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/doctrine-user. For more options, visit https://groups.google.com/d/optout.
