Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-3034

QueryBuilder invalid number of bound params

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Invalid
    • Affects Version/s: 2.4.2
    • Fix Version/s: None
    • Component/s: ORM
    • Security Level: All
    • Labels:
    • Environment:
      PHP 5.4.16, Zend Framework 2.2.5, Doctrine ORM Module 0.8.0

      Description

          /**
           * @param int  $companyId
           * @param bool $includeDeleted
           * @return \Doctrine\ORM\QueryBuilder
           */
          public function findCompanySubjects($companyId, $includeDeleted = false)
          {
              $qb=$this->createQueryBuilder('t')
                  ->addSelect('owner')
                  ->innerJoin('t.owner', 'owner')
                  ->innerJoin('owner.company', 'company')
                  ->andWhere('t.deleted = :deleted')
                  ->andWhere('company.id = :id')
                  ->orderBy('t.name', 'asc')
      
                  ->setParameter('deleted', $includeDeleted)
                  ->setParameter('id', $companyId)
              ;
      
              return $qb;
          }
      

      Code above does not work for me. I'm still getting an error "Invalid parameter number: number of bound variables does not match number of tokens". However, bound parameters does work with raw DQL and the Query object.

        Activity

        Hide
        Marco Pivetta added a comment -

        Mike Zukowsky what is the complete DQL that is produced for that query? And does it work with a DQL query written directly (rather than the QB)?

        Show
        Marco Pivetta added a comment - Mike Zukowsky what is the complete DQL that is produced for that query? And does it work with a DQL query written directly (rather than the QB)?
        Hide
        Mike Zukowsky added a comment -

        Raw DQL is:

        SELECT t, owner FROM Domain\Entity\Subject t INNER JOIN t.owner owner INNER JOIN owner.company company WHERE t.deleted = :deleted AND company.id = :id ORDER BY t.name asc
        

        And yes, it does work with a DQL query written directly:

                // $qb from above
        
                $query=$qb->getQuery()->setParameters(array(
                    'deleted' => $includeDeleted,
                    'id'      => $companyId
                ));
        
                debug($query->getArrayResult()); // returns a list of subjects
        
        Show
        Mike Zukowsky added a comment - Raw DQL is: SELECT t, owner FROM Domain\Entity\Subject t INNER JOIN t.owner owner INNER JOIN owner.company company WHERE t.deleted = :deleted AND company.id = :id ORDER BY t.name asc And yes, it does work with a DQL query written directly: // $qb from above $query=$qb->getQuery()->setParameters(array( 'deleted' => $includeDeleted, 'id' => $companyId )); debug($query->getArrayResult()); // returns a list of subjects
        Hide
        Marco Pivetta added a comment -

        You are returning the QB in your reported code - I'm pretty sure that some interaction with it is going on at a later point in time.

        Could you provide the code that is causing the problem? Otherwise, this doesn't look like a bug to me.

        Show
        Marco Pivetta added a comment - You are returning the QB in your reported code - I'm pretty sure that some interaction with it is going on at a later point in time. Could you provide the code that is causing the problem? Otherwise, this doesn't look like a bug to me.

          People

          • Assignee:
            Marco Pivetta
            Reporter:
            Mike Zukowsky
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: