I'm trying to personalize a symfony 2.4 repository query to retrieve only some fields. Everything is ok with flat fields but when retrieving Entity fields, I only get the id (by default) but not the whole entity data. My query:
    $select = $this->createQueryBuilder('ca')
    ->select('ca.id, ca.name')
    ->leftJoin('ca.users', 'user')
    ->addSelect('(user) as users'); 
    $select->setMaxResults($count);
    return $select->getQuery()->getResult();
The result is: [{id: 1, name: "Some name", users: 1}, ...]
How can I change this query for users to contain the whole user data, like id, name, address, etc.?
This works for me:
$select = $this->createQueryBuilder('ca')
    ->select('partial ca.{id, name}, users')
    ->leftJoin('ca.users', 'users');
$select->setMaxResults($count);
return $select->getQuery()->getArrayResult();
                        You should try this way. You can use Partial.
$select = $this->createQueryBuilder('ca')
->select('partial ca.{id, name}')
->leftJoin('ca.users', 'users')
->addSelect('users'); 
A detailed description of this issue is available here. Doctrine2: Cannot select entity through identification variables without choosing at least one root entity alias
change this:
->select('ca.id, ca.name')
to this:
->select('ca')
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With