partial select doctrine query builder

前端 未结 1 1463
予麋鹿
予麋鹿 2021-01-07 08:25

I\'m trying to custom select use this code

$result = $qb->select(\'partial user.{id,name}\')
                 ->from(\'User\', \'user\')
                       


        
相关标签:
1条回答
  • 2021-01-07 08:55

    Using the DQL "partial" keyword is not enough to get a partial entity as a result.

    The DQL hint HINT_FORCE_PARTIAL_LOAD must be used as well.

    $query = $qb->select('partial user.{id,name}')
                 ->from('User', 'user')
                 ->leftJoin('user.group', 'group')
                 ->getQuery()
    ;
    
    $query->setHint(Doctrine\ORM\Query::HINT_FORCE_PARTIAL_LOAD, 1);
    
    $results = $query->getResult();
    
    0 讨论(0)
提交回复
热议问题