doupu1727 2015-07-09 18:08
浏览 45
已采纳

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?

  • 写回答

1条回答 默认 最新

  • douxue4242 2015-07-09 18:10
    关注

    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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥200 如何使用postGis实现最短领规划?
  • ¥15 pyinstaller打包错误
  • ¥20 cesm的气溶胶排放文件
  • ¥15 逐月累计,月份不连续,补齐月份
  • ¥15 应用简单的Python代码完成一个学生成绩管理系统
  • ¥15 用matlab求微分方程初值问题
  • ¥15 vscode下编写第三方库opencv与pcl代码时没有代码提示
  • ¥15 能够跑通不报错,如何解决?(标签-matlab)
  • ¥15 MOS在RDS较大,频率高时开关波形异常
  • ¥15 SCENIC分析报错求解答