Disable Doctrine 2 lazy loading when using JMS Serializer?

前端 未结 5 1315
梦谈多话
梦谈多话 2020-12-05 11:24

Im using Doctrine 2 ORM in my Zend project and need to serialize my Entities to JSON in several cases.

ATM i use the Querybuilder and join all tables i need. But my

5条回答
  •  借酒劲吻你
    2020-12-05 12:03

    When using Doctrine's query builder, you can't disable lazy loading of linked model classes. If you want to bypass such behavior, you better have to request data with Doctrine's DBAL.

    Don't use \Doctrine\ORM\QueryBuilder but \Doctrine\DBAL\Query\QueryBuilder.

    $qb = new QueryBuilder($this->_em->getConnection());
    $expr = $qb->expr();
    
    $qb->select('pa.*', 't.*', 'c.*', 'a.*', 'aps.*', 'apt.*', 'p.*')
       ->from('person_appointment', 'pa')
       ->leftJoin('pa', 'table', 't', $expr->eq('pa.table_id', 't.table_id'))
       // put other joints here
       // ...
       ->leftjoin('a', 'person', 'p', $expr->eq('a.person_id', 'p.person_id'));
    

提交回复
热议问题