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有參考的發票。發票參照商店
我試圖讓訪問發票對象(其中工程目前),但後來接觸到存儲對象的發票對象保存。
如果我可以在問題中進一步澄清,請讓我知道。感謝您提前查看。 –