The problem seems to reside in your Entities. You need to add proper annotations to your entities, if you want DQL to work they way it was designed to work.
It seems like you're facing the classic One-To-Many, Unidirectional problem:
For example:
Users.php:
<?php
/**
*@ORM\Table("Users")
*@ORM\Entity
*/
class Users {
/**
* @ORM\ManyToMany(targetEntity="Role")
* @ORM\JoinTable(name="users_roles",
* joinColumns={@JoinColumn(name="user_id", referencedColumnName="id")},
* inverseJoinColumns={@JoinColumn(name="role_id", referencedColumnName="id")}
* )
*/
private $roles;
public function __construct() {
$this->roles = new ArrayCollection();
}
}
Then it should be just a matter of writing a DQL like:
$query = $em->createQuery('
SELECT
u.username, u.roles.role
FROM
TestLoginBundle:User u
WHERE
u.username = :user
')->setParameter('user', $name);
In order to get the results you want.
Read the following page in Doctrine's documentation:
http://docs.doctrine-project.org/en/2.0.x/reference/association-mapping.html
They provide more in depth and thorough examples, than the one shown above. However, if you plan to use these examples in Symfony. Remember to prepend @ORM\
to all the annotations shown in Doctrine's docs.
For example, if Doctrine's documentation tells you to use:
/**
* ManyToMany(targetEntity="Role")
*/
Then in symfony, you have to write it like:
/**
* @ORM\ManyToMany(targetEntity="Role")
*/
Otherwise, it won't work.