Doctrine Query Builder не регистрирует параметр? - PullRequest
0 голосов
/ 10 ноября 2011

У меня есть следующий код, который выбрасывает исключение Invalid parameter number: number of bound variables does not match number of tokens.Тем не менее, когда я печатаю зарегистрированные параметры, мой параметр отображается.

<code>public function getUnitPriceFor($entityType,$entityID,$qty,$configuration_id)
{
    $this->qb = $this->getEntityManager()->createQueryBuilder();
    $this->qb   ->select($this->_entities[$entityType]['select'])
                // for Base this would be ->select(array('t','c','w','g'))
                // for the other cases below, like website, it's array('t','w')
                ->from('AcmeBundle:PriceTier', 't');

    switch($entityType) :
        case 'base' :
            $this->qb   ->leftJoin('t.customers','c')
                        ->leftJoin('t.customergroups','g')
                        ->leftJoin('t.websites','w');
        break;
        case 'website' :
            $this->qb   ->join('t.websites','w','WITH','w.id = '.$entityID);
        break;
        case 'custgrp' :
            $this->qb   ->join('t.customergroups','g','WITH','g.id = '.$entityID);
        break;
        case 'cust' :
            $this->qb   ->join('t.customers','t','WITH','t.id = '.$entityID);
        break;
    endswitch;

    $this->qb           ->where('t.printconfiguration = :configuration_id');
    $this->qb           ->setParameter('configuration_id', $configuration_id);

    print_r( $this->qb->getParameters() );

    $dql = $this->qb->getDQL();

    echo"<pre>";
    print_r($this->getEntityManager()->createQuery($dql)->getArrayResult());
    echo"
";}

Печать $this->qb->getParameters(); показывает мне Array ( [configuration_id] => 1 ) и удаляет мои предложения where и set для параметровпредотвращает возникновение исключения. Наконец, (и получаю это), если я удаляю свое предложение where, но сохраняю набор параметров, исключение не возникает. Я довольно запутался.

1 Ответ

1 голос
/ 10 ноября 2011

Видимо $dql = $this->qb->getDQL(); не будет передавать параметры.

Мне нужно было изменить

<code>$dql = $this->qb->getDQL();

echo"<pre>";
print_r($this->getEntityManager()->createQuery($dql)->getArrayResult());
echo"
";

до

<code>$query = $this->qb->getQuery();

echo"<pre>";
print_r($query->getArrayResult());
echo"
";
...