[英]DQL Access Property of Property in Query Builder (Doctrine)
我將以下查詢匯總在一起。
$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具有對Invoice的引用。 發票已參考商店
我正在嘗試訪問發票對象(當前可用),但隨后訪問發票對象所擁有的商店對象 。
我找到了問題的答案
$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代碼確實有效。 這比嘗試離開我的情況要好。 雖然我的問題在技術上沒有得到回答,但這是解決我的問題的方法。 我仍然想知道是否有可能在您已經離開加入的屬性上離開加入?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.