问题描述
我已经失去了这三个小时的谷歌这个,但没有一个解决方案是好的。我有这个querybuilder:
$ qb2 = $ this-> createQueryBuilder('s')
- > addSelect('u')
- > innerJoin('s'用户','u')
- > where(u.id IN(:followeeIds))
- > andWhere('s.admin_status = false')
- > ; setParameter('user',$ user)
- > setParameter('followeeIds',$ arrayFolloweeIds)
- > orderBy('s.id','DESC')
- > setMaxResults(15)
;
我可以做一个第二个查询,然后像 $ qb-> getDQL()
但是我会缓存查询吗?
错误:
参数号无效:绑定变量的数量不符合令牌数
您正在设置用户参数,但我没有看到它在任何地方在查询中使用
另外我有问题使用数组的 WHERE IN
和Doctrine QueryBuilder
会给我一个类似的错误,奇怪的是运行 array_values
在绑定参数之前,似乎也解决了这些问题。
尝试:
$ qb2 = $ this-> createQueryBuilder('s')
- > addSelect('u')
- > innerJoin('s.user','u')
- > where(u.id IN(:followeeIds))
- > andWhere('s.admin_status = false')
- > setParameter('followeeIds',array_values($ arrayFolloweeIds))
- > orderBy('s.id','DESC')
- > setMaxResults(15)
;
I losted trilion hours google this but none of the solutions were good.
I have this querybuilder:
$qb2=$this->createQueryBuilder('s')
->addSelect('u')
->innerJoin('s.user','u')
->where("u.id IN(:followeeIds)")
->andWhere('s.admin_status = false')
->setParameter('user', $user)
->setParameter('followeeIds', $arrayFolloweeIds)
->orderBy('s.id','DESC')
->setMaxResults(15)
;
I could do a second query and then do like $qb->getDQL()
but have would i cache the query ?
Error:
Invalid parameter number: number of bound variables does not match number of tokens
You are setting the user parameter but I do not see it being used in the query anywhere?
Also I had issues with WHERE IN
and Doctrine QueryBuilder
with arrays would give me a similar error, and oddly enough running array_values
before binding the parameter seemed to solve those issues as well.
Try:
$qb2=$this->createQueryBuilder('s')
->addSelect('u')
->innerJoin('s.user','u')
->where("u.id IN(:followeeIds)")
->andWhere('s.admin_status = false')
->setParameter('followeeIds', array_values($arrayFolloweeIds))
->orderBy('s.id','DESC')
->setMaxResults(15)
;
这篇关于Symfony2学说querybuilder其中IN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!