2

I have two entities: People and Document

A people can have n childrens:

/**
 *
 * @ORM\ManyToOne(targetEntity="People")
 * @ORM\JoinColumns({
 *   @ORM\JoinColumn(name="dad_id", referencedColumnName="id")
 * })
*/
private $dad;


/**
 *
 * @ORM\OneToMany(targetEntity="People", mappedBy="dad")
*/
private $childrens;

And a people can have n Documents:

DocumentEntity:

/**
 *
 * @ORM\ManyToOne(targetEntity="People")
 * @ORM\JoinColumns({
 *   @ORM\JoinColumn(name="people_id", referencedColumnName="id")
 * })
 */
private $people;

I want to get all peoples (and their children) and their documents of type License in one query:

$qb = $this->em->getRepository('People')->createQueryBuilder('p');
$qb
    ->select(array('p','d'))
    ->leftJoin('p.documents','d','WITH','d.type = :type')
    ->setParameter('type','license')      
;

$peoples = $qb->getQuery()->getResult();

Fine, if i call $people->getDocuments() returns only Documents of type 'License'. But when i do this '$people->getChildrens()[0]->getDocuments()' returns for me all Documents of this people.

How i can do a 'left join WITH' cascading on a tree structure?

Ciro Vargas
  • 422
  • 1
  • 5
  • 16

0 Answers0