Symfony Doctrine通过另一个实体获取实体

I have 3 entities: User, ImaginaryBankAccount and Recharge. One user has one ImaginaryBankAccount and ImaginaryBankAccount can have more than one Recharges. And I want to select from DB all Recharges that belongs to one user.

I have this query:

$resResults = $query->getResult();
$query = $em->createQuery('SELECT rec
                           FROM AppBundle:Recharge rec
                           WHERE rec.dateTime > :tresholdDate
                            AND rec.imaginaryBankAccount.user = :user
                           ORDER BY rec.dateTime'
)->setParameter('tresholdDate', $dateXDaysBack)
 ->setParameter('user', $filter->getUser());
$recResults = $query->getResult();

But it throws error:

[Semantical Error] line 0, col 223 near 'user = :user ': Error: Class AppBundle\Entity\Recharge has no field or association named imaginaryBankAccount.user

How can I achieve my goal with Doctrine2?

You have to add a JOIN clause with your imaginaryBankAccount relation like this :

SELECT rec
FROM AppBundle:Recharge rec
JOIN rec.imaginaryBankAccount i
WHERE rec.dateTime > :tresholdDate
AND i.user = :user
ORDER BY rec.dateTime