DQL访问属性在查询生成器(原则)
问题描述:
我有以下查询我放在一起。DQL访问属性在查询生成器(原则)
$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有参考的发票。发票参照商店
我试图让访问发票对象(其中工程目前),但后来接触到存储对象的发票对象保存。
答
我找到了答案,我的问题
$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确实工作。这比在我的情况下试图离开更好。虽然我的问题没有技术上的答案,但这是解决我的问题的方法。 我仍然好奇,如果它可能离开你已经离开的财产加入?
如果我可以在问题中进一步澄清,请让我知道。感谢您提前查看。 –