我将以下查询放在一起。
$lineItems = $em->createQueryBuilder()->select('invitems.unitprice,invitems.quantity,invitems.tax,invitems.scrapetax')
->from('AppBundle:InvoiceLineItems', 'invitems')
->leftJoin('invitems.invoiceId','inv') //StoreID is present in the invoice so only need to leftjoin here
->leftJoin('inv.storeId','si')
->where('inv.companyId = :companyId')
->andWhere('si.id = :storeId')
->andWhere('inv.created BETWEEN :startdate AND :enddate')
->andWhere("inv.status = 'sent' or inv.status = 'paid' or inv.status = 'partial' ")
->setParameter('startdate', $startDate)
->setParameter('enddate', $endDate)
->setParameter('companyId',$companyid)
->setParameter('storeId',$store['id'])
->getQuery()
->getResult();
查询运行时没有崩溃但不起作用,因为我知道我有属于发票商店的数据库条目。它目前返回0个条目。我验证了$ store ['id']提供了正确的ID,所以它不是一个愚蠢的错误。删除该行及其参数引用否则返回行。
问题在于这一行->leftJoin('inv.storeId','si')
我是否可以离开加入来自另一个左连接的属性?我需要这样做的原因是,lineitems没有引用storeID而只有发票。
我无法在文档中找到有关此主题的任何内容。
我也尝试了这一点但没有任何成功。
->andWhere('inv.storeId = :storeId')
基本上我要做的是:
InvoiceLineItems 引用了发票。发票参考了商店
我正在尝试访问发票对象(当前有效),但随后可以访问发票对象所持有的商店对象。
答案 0 :(得分:0)
我找到了问题的答案
$lineItems = $em->createQueryBuilder()->select('invitems.unitprice,invitems.quantity,invitems.tax,invitems.scrapetax')
->from('AppBundle:InvoiceLineItems', 'invitems')
->leftJoin('invitems.invoiceId','inv') //@JA - StoreID is present in the invoice, only need to leftjoin in this case
->where('inv.companyId = :companyId')
->andWhere('inv.storeId = :storeId')
->andWhere('inv.created BETWEEN :startdate AND :enddate')
->andWhere("inv.status = 'sent' or inv.status = 'paid' or inv.status = 'partial' ")
->setParameter('startdate', $startDate)
->setParameter('enddate', $endDate)
->setParameter('companyId',$companyid)
->setParameter('storeId',$store["id"])
->getQuery()
->getResult();
事实证明代码inv.storeId正常工作。这比在我的情况下试图离开加入更好。虽然我的问题在技术上没有得到解答,但这是我的问题的解决方案。 我仍然很好奇是否有可能将你留在你已经离开的房产上?