I’m trying to join a table that has no association defined in my config file. Why? Because I don’t want to pollute this entity (Section) because many other entity can be related to this one with a “Many to One” relation. So, I define the relation only on one side, so it doesn’t pollute my Section entity.
What I’m trying to do is :
// Find all sections with this bundle linked
$query = $this->getEntityManager()->getRepository('CompanyBackendSectionBundle:Section')->createQueryBuilder('s')
->select('s', 'st')
->innerJoin('s.translations', 'st')
->innerJoin('s.sectionBundles', 'sb')
->innerJoin('Company\Backend\FaqBundle\Entity\FaqQuestion', 'fq')
->where('st.locale = :locale')
->andWhere('sb.bundle = :bundleId')
->orderBy('st.name')
->setParameters(array(
'locale' => $this->getLocale(),
'bundleId' => $bundle->getId()
));
The problem is with “->innerJoin(‘Company\Backend\FaqBundle\Entity\FaqQuestion’, ‘fq’)”, I got :
[Semantical Error] line 0, col 179 near 'fq WHERE st.locale': Error: Identification Variable Company\Backend\FaqBundle\Entity\FaqQuestion used in join path expression but was not defined before.
Is there a way to do it other than using Doctrine Native Query?
No. Doctrine Query Language needs you to define the relation in the direction you wanna use it…