多个连接查询构建器doctrine2

kor*_*nko 1 sql query-builder symfony doctrine-orm

 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();
    }
Run Code Online (Sandbox Code Playgroud)

查询返回错误:

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

Ale*_* B. 6

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