当我尝试在控制器中使用它时出现以下错误
App\Repository\AccountRepository::findOneByAccountCode() 的返回值必须是 App\Repository\Bank 的实例或 null,返回 App\Entity\Account 的实例
/**
* @param Request $request
* @param string $accountCode
* @return Response
* @throws EntityNotFoundException
*/
public function somefunction(Request $request, string $accountCode)
{
/** @var BankRepository $acRepository */
$acRepository = $this->getDoctrine()->getRepository(Account::class);
$bank = $acRepository->findOneByAccountCode($accountCode);
}
存储库代码
public function findOneByAccountCode(string $accountCode): ?Bank
{
try {
return $this->createQueryBuilder('a')
->innerJoin('a.bank', 'b')
->where('a.code = :code')
->setParameter('code', $accountCode)
->getQuery()
->getOneOrNullResult();
}catch (NonUniqueResultException $e) {
return null;
}
}