Sepideh
Sepideh

Reputation: 133

partial select doctrine query builder

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?!

Upvotes: 3

Views: 14582

Answers (1)

scoolnico
scoolnico

Reputation: 3135

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();

Upvotes: 7

Related Questions