partial select doctrine query builder

2019-06-09 13:34发布

I'm trying to custom select use this code

$result = $qb->select('partial user.{id,name}')
                 ->from('User', 'user')
                 ->leftJoin('user.group', 'group')
                 ->getQuery()
                 ->getResult(); 

the result of this code in below

{
    "id": 10,
    "name": "admin",
    "description": null,
    "create_date": null,
    "modified_date": null,
}

why returned field not selected with null value?!

1条回答
何必那么认真
2楼-- · 2019-06-09 14:22

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();
查看更多
登录 后发表回答