简体   繁体   中英

Left join in doctrine orm Zend framework

I have this query below:

SELECT * 
FROM mydb.users
left join mydb.jobs
on users.user_id = jobs.job_id;

And I used to convert them in orm query just like below:

  return 
  $qb = $this->entityManager->createQueryBuilder();
  $qb->select('rb', 'l')
     ->from('Admin\Entity\Users', 'rb')
     ->leftJoin(
        'Admin\Entity\Jobs',
        'l',
        \Doctrine\ORM\Query\Expr\Join::WITH,
        'rb.user_id = l.job_id'
       )
     ->getQuery()
     ->getResult(AbstractQuery::HYDRATE_ARRAY); 

But it doesn's still work. I get the following error:

PHP Fatal error: Call to a member function createQueryBuilder() on null

please help i don't know what to do.

Try this

$entityManager = $this->serviceLocator->get('Doctrine\ORM\EntityManager');
$qb = $entityManager->createQueryBuilder();

Or make sure $this->entityManager is assigned.

Well it simply means you don't have an EntityManager instance in $this->entityManager .

My guess would be that $this->entityManager is probably null because you did not inject an EntityManager inside your class instance.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM