两个表之间的Doctrine2 innerJoin没有定义关联

时间:2012-03-06 14:44:25

标签: symfony doctrine-orm

我正在尝试加入一个在我的配置文件中没有定义关联的表。为什么?因为我不想污染这个实体(部分),因为许多其他实体可以与这个实体相关,并且具有“多对一”关系。因此,我只在一侧定义关系,因此它不会污染我的Section实体。

我要做的是:

// 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()
          ));

问题在于“ - > innerJoin('Company \ Backend \ FaqBundle \ Entity \ FaqQuestion','fq')”,我得到了:

[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.

除了使用Doctrine Native Query之外,还有办法吗?

1 个答案:

答案 0 :(得分:3)

没有。 Doctrine查询语言需要您在想要使用它的方向上定义关系......

相关问题