1

I have query with two MtM relations:

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

But it gives me error: Invalid parameter number: number of bound variables does not match number of tokens. Can anybody explain me what is wrong? Relation in User model:

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

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

1 Answer 1

3

I think the reason is because you used where twice. That overwrites the first where, which is why it is giving you the parameters number error.

Use andWhere

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.