php – symfony2 doctrine expr子查询:错误:参数号无效

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – symfony2 doctrine expr子查询:错误:参数号无效脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
试图让用户获得喜欢的状态.

public function getLikedstatuses(User $user)
{
    $qb = $this->_em->createQueryBuilder();
                $qb
                ->select('s.id')
                ->From('WallBundle:Likes','l')
                ->innerJoin('l.status','s')
                ->where('l.user = :user')
                ->setParameter('user',$user)
                ->orderBy('s.id','DESC')
            ;

    $qb2=  $this->_em->createQueryBuilder()
        ->select('st')
        ->from('WallBundle:Status','st');

       $qb2 ->andWhere($qb2->exPR()->in('st.id',$qb->getDQL()));


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

BTW:当我转储$qb-> getDQL()时:

string 'SELECT s.id FROM TB\WBundle\EntITy\Likes l LEFT JOIN l.status s WHERE l.user = :user' (length=87)

BTW2:当我为'(12073)(状态的id)替换’$qb-> getDQL()’时,它的工作原理……

解决方法

实际上,您可以执行更简单查询,具体取决于您的注释方式.

就像是 :

$qb =  $this->_em->createQueryBuilder()
    ->select('s')
    ->from('WallBundle:Status','st')
    ->innerJoin('st.like','l')
    ->where('l.user = :user')
    ->setParameter('user',$user)
    ->getQuery()
    ->getResult();

应该做同样的事情,更短,更容易理解,因为只有一个查询.

更新:我遇到了与今天完全相同的问题,并通过将两个setParameters放在第二个查询中来解决它.因此我找到了解决它的另一种方法

我做了类似的事情:

$qb = $this->_em->createQueryBuilder()
    ->select('s.id')
    ->from('WallBundle:Likes','l')
    ->innerJoin('l.status','s')
    ->where('l.user = :user')
    ->orderBy('s.id','DESC')
    ->getDQL()
;

$qb2=  $this->_em->createQueryBuilder()
    ->select('st')
    ->from('WallBundle:Status','st');
    ->where('st.like in('.$qb.')')
    ->setParameter('user',$user)
    ->getQuery()
;

脚本宝典总结

以上是脚本宝典为你收集整理的php – symfony2 doctrine expr子查询:错误:参数号无效全部内容,希望文章能够帮你解决php – symfony2 doctrine expr子查询:错误:参数号无效所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。