参数无效:令牌帐户未在查询中定义
Invalid parameter: token account is not defined in the query
我定义了两个查询构建器。
首先:Returns一个用户的所有账户。
秒:Returns 帐户的所有用户交易。
第一个:
public function getAccountsList($user)
{
return $this->getAccountRepository()
->createQueryBuilder('a')
->select('a')
->where('a.user = :user')
->setParameter('user', $user)
->getQuery()
->getResult();
}
第二个:
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;
}
第一次运行完美但第二次抛出错误:
Invalid parameter: token account is not defined in the query
如何解决?
您的账户参数有误
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;
}
如你所见...
->where('t.account IN (:accounts)')
->setParameter('account', $accounts)
一个是accounts,一个是account。应该是:
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;
}
token account is not defined in the query
这意味着 ->setParameter('account', ...)
是查询的任何地方
在您的 ->where
中,您设置了带有 S
和结尾的令牌 :accounts
,拼写错误
正确答案是
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;
}
我定义了两个查询构建器。
首先:Returns一个用户的所有账户。
秒:Returns 帐户的所有用户交易。
第一个:
public function getAccountsList($user)
{
return $this->getAccountRepository()
->createQueryBuilder('a')
->select('a')
->where('a.user = :user')
->setParameter('user', $user)
->getQuery()
->getResult();
}
第二个:
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;
}
第一次运行完美但第二次抛出错误:
Invalid parameter: token account is not defined in the query
如何解决?
您的账户参数有误
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;
}
如你所见...
->where('t.account IN (:accounts)')
->setParameter('account', $accounts)
一个是accounts,一个是account。应该是:
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;
}
token account is not defined in the query
这意味着 ->setParameter('account', ...)
是查询的任何地方
在您的 ->where
中,您设置了带有 S
和结尾的令牌 :accounts
,拼写错误
正确答案是
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;
}