'How can I restrict certain entities from my queryBuilder?

I'm trying to use a queryBuilder to get some users who did NOT have an appointment with subject 'PC' ("Prise de Contact"). and fit certain criteria of appointment dates ina related entity, "Amont".

I'm reusing a queryBuilder using "clone" so I can perform my search on the result of the queryBuilder that was made for displaying the page. I'm trying to use the notIn() method from the expressions of queryBuilder

    $nots
    ->leftJoin('u.rendezVouses', 'rdv')
    ->andWhere("rdv.objetRDV = 'PC'");

    $qb
    ->select('u.id')
    ->leftJoin('u.amonts', 'a')
    ->andWhere($qb->expr()->notIn('u.id', $nots))
    ->andWhere('a.datePremierRDV <= :dateNj')
    ->andWhere('a.datePremierRDV >= :dateMini')
    ->andWhere($qb->expr()->isNotNull('a.datePremierRDV'))
    ->setParameter('dateNj', $dateNj)
    ->setParameter('dateMini', $dateMini);

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

here's the error message I get in symfony profiler:

Error: Method Doctrine\Common\Collections\ArrayCollection::__toString() must not throw an exception, caught ErrorException: Catchable Fatal Error: Object of class Doctrine\ORM\EntityManager could not be converted to string



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source