doujing8435 2019-06-12 11:45
浏览 30
已采纳

参数无效:查询中未定义令牌帐户

I have two query builders defined.

First: Returns all accounts of an user.

Seconds: Returns all user transactions by account.

First:

public function getAccountsList($user)
{
    return $this->getAccountRepository()
        ->createQueryBuilder('a')
        ->select('a')
        ->where('a.user = :user')
        ->setParameter('user', $user)
        ->getQuery()
        ->getResult();
}

Second:

 public function  getTransactionsList($user)
{
    $accounts = $this->getAccountsList($user);

    $query = $this->getTransactionRepository()
        ->createQueryBuilder('t')
        ->select('t')
        ->where('t.account IN (:accounts)')
        ->setParameter('account', $accounts)
        ->getQuery()
        ->getResult();

    return $query;
}

First works perfect but second throws an error:

Invalid parameter: token account is not defined in the query

How to fix it?

  • 写回答

2条回答 默认 最新

  • doulai1910 2019-06-12 11:49
    关注

    token account is not defined in the query

    That mean ->setParameter('account', ...) is anywhere is the query

    in your ->where you have set the token :accounts with the S and the end, typo error

    Correct answer is

    public function  getTransactionsList($user) {
        $accounts = $this->getAccountsList($user);
    
        $query = $this->getTransactionRepository()
            ->createQueryBuilder('t')
            ->select('t')
            ->where('t.account IN (:accounts)')
            ->setParameter('accounts', $accounts)
            ->getQuery()
            ->getResult();
    
        return $query;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试