多个连接查询构建器doctrine2

时间:2013-08-20 07:40:47

标签: sql symfony doctrine-orm query-builder

 public function search($params)
    {
        $qb = $this->createQueryBuilder('auto');
        if (isset($params['manufacturer'])) {
            $qb->join('auto.manufacturer', 'man')
            ->where('man.manufacturer = :manufacturer')
            ->setParameter('manufacturer', $params['manufacturer']);
        }
        if (isset($params['model'])) {
            $qb->join('auto.model', 'mod')
                ->where('mod.model = :model')
                ->setParameter('model', $params['model']);
        }

        return $qb->getQuery()->getResult();
    }

查询返回错误:

  

参数号无效:绑定变量数不匹配   令牌数量

1 个答案:

答案 0 :(得分:6)

where替换为andWhere功能。因为当你有2个参数时,你首先将where where条件替换为where where条件,结果你有2个绑定参数只有一个标记。