I have an Entity that looks like this:
class Privilege { private $id; private $name; private $slug; private $children; private $parent;
If a Privilege Entity does not have a parent, the field is NULL. I have a basic request:
$qb = $this->em->createQueryBuilder() ->select('p') ->from('\Dashboard\Entity\Privilege', 'p') ->andWhere('p.parent IS NULL'); $q = $qb->getQuery(); $privileges = $q->getResult();
I would like the array result to be returned from this method, to look something like this:
root1: child1: subchild1a subchild2a child2: subchild1b subchild2b subchild3b subsubchild1b child3: subchild1c root2: .... ....
Is there a way to get data from Doctrine 2 to get the results of an array this way? If not, how would you build this array? I'm still playing with Doctrine 2, and I noticed that every element in my $privileges array has $privilege->getChildren() , which returns a PersistentCollection , not the actual record.
If I need to build this nested tree myself (i.e. not built into Doctrine), how can I return this PersistentCollection to the actual data so that I can build some kind of recursive method for assembling this for me? I am looking through documents, but obviously in the wrong place.
source share