This is my query with query builder, and it works perfectly, bringing all the results of user table and the modules table, which has a many to many association:
public function getUser($id){
$qb = $this->getEm()->createQueryBuilder()
->select('u', 'm')
->from('Adm\Entity\User', 'u')
->join('u.modules', 'm')
->where('u.id = ?1')
->setParameters(array(1 => $id));
$result = $qb->getQuery()->getResult(\Doctrine\ORM\AbstractQuery::HYDRATE_ARRAY);
return $result;
}
But when i try to select specific fields from user like this:
public function getUser($id){
$qb = $this->getEm()->createQueryBuilder()
->select('u.id, u.name, u.email', 'm')
->from('Adm\Entity\User', 'u')
->join('u.modules', 'm')
->where('u.id = ?1')
->setParameters(array(1 => $id));
$result = $qb->getQuery()->getResult(\Doctrine\ORM\AbstractQuery::HYDRATE_ARRAY);
return $result;
}
Doctrine throws an error:
[Semantical Error] line 0, col -1 near 'SELECT u.id,': Error: Cannot select entity through identification variables without choosing at least one root entity alias.
I would like to know how to do that, to select specific fields from the entity and not all the fields.