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 python验证码滑块图像识别
  • ¥15 QT6颜色选择对话框显示不完整
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)