doctrine 2多个连接在一个查询中给我错误

时间:2012-03-25 06:19:50

标签: symfony many-to-many doctrine-orm

我有两个MtM关系的查询:

        $em = $this->getEntityManager();

        $qb = $em->createQueryBuilder();
        $qb
            ->select('o')
            ->from('UserBundle:User', 'o')
            ;

        $qb->join('o.organisations', 'org')
            ->where('org.id = :organisation')
            ->setParameter('organisation', $filterData['organisation'])
        ;
        $qb
            ->join('o.scientificDirections', 'd')
            ->where('d.id IN (:directionIds)')
            ->setParameter('directionIds', $directionIds)
            ->orderBy('o.surname')
            ;
        return $qb->getQuery();

但是它给了我错误:参数号无效:绑定变量的数量与令牌数量不匹配。 任何人都可以解释我有什么问题吗? 用户模型中的关系:

/**
 * @ORM\ManyToMany(targetEntity="\StrangeBundle\Entity\ScientificDirection")
 *
 */
protected $scientificDirections;

/**
 * @ORM\ManyToMany(targetEntity="\StrangeBundle\Entity\Organisation", mappedBy="workers")
 */
protected $organisations;

1 个答案:

答案 0 :(得分:3)

我认为原因是因为你曾两次使用where。这会覆盖第一个,这就是为什么它会给你参数编号错误。

使用andWhere