Symfony2 Doctrine 查询构建器在哪里 [英] Symfony2 Doctrine querybuilder where IN

查看:18
本文介绍了Symfony2 Doctrine 查询构建器在哪里的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在谷歌上浪费了三亿小时,但没有一个解决方案是好的.

I losted trilion hours google this but none of the solutions were good.

我有这个查询生成器:

        $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)
    ;

我可以做第二个查询,然后像 $qb->getDQL() 但我会缓存查询吗?

I could do a second query and then do like $qb->getDQL() but have would i cache the query ?

错误:

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?

我也遇到了 WHERE IN 和 Doctrine QueryBuilder 与数组的问题,这会给我一个类似的错误,奇怪的是在绑定之前运行 array_values该参数似乎也解决了这些问题.

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.

尝试:

$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 Doctrine 查询构建器在哪里的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆