2017-10-28 141 views
0

我有以下查詢我放在一起。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有參考的發票。發票參照商店

我試圖讓訪問發票對象(其中工程目前),但後來接觸到存儲對象的發票對象保存。

+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確實工作。這比在我的情況下試圖離開更好。雖然我的問題沒有技術上的答案,但這是解決我的問題的方法。 我仍然好奇,如果它可能離開你已經離開的財產加入?