I'm making a query using the QueryBuilder
object from Doctrine. In that query I have a join
which I don't know why, gives me an error saying that the alias (fe
) for one of the tables (F_Expenses
) is not defined. In SQL, my query would looks like this:
select * from f_expenses
join users_f_expenses on f_expenses.id=users_f_expenses.id_form
where login="Jack1234";
This being said, this is the function which contains my QueryBuilder
object:
public function getFormsAction($login){
$em = $this->getDoctrine()->getEntityManager();
$qb = $em->createQueryBuilder()
->select('fe')
->from('intranetBundle:Entity\F_Expenses', 'fe')
->innerJoin('fe', 'intranetBundle:Entity\Users_F_Expenses', 'ufe', 'fe.id = ufe.idForm')
->where('ufe.login = :login')
->setParameter('login', $login)
->getQuery();
$formsOfTheUser = $qb->getArrayResult();
$serializer = SerializerBuilder::create()->build();
$serializer->serialize($formsOfTheUser, 'json');
return $formsOfTheUser;
}
Note that yes, the field called id_form
in the database, is named as idForm
in the Entity. This is exactly the error:
[Semantical Error] line 0, col 62 near 'fe intranetBundle:Entity\Users_F_Expenses': Error: Class 'fe' is not defined.
I've just followed the API, first argument of the join
is used to specify the alias of the FROM
, so fe
. Second and third parameters are, respectively, the join-table and its alias (so intranetBundle:Entity\Users_F_Expenses
and ufe
), and finally the fourth is the on
clause (fe.id = ufe.idForm
).
I've tried to delete the join
line and make a normal select
from the first table and it worked, so I'm pretty sure that the error has something to do with the join
clause.