我有四个表,EdiTransaction,EdiTransactionDetail,EdiDocType和Edi997Details,其中EdiTransaction表与EdiDocType和EdiTransactionDetail有关系,但Edi997Details只与EdiTransaction有关系,其他人没有(请点击请参阅下面的图片)我正在制作一个页面,其中所有的EdiTransaction都带有相应的DocType 856/810,带有PO编号的EdiTransactionDetail和它的Edi997Details。现在我非常坚持如何使用EdiTransaction表检索/加入Edi997Details,因为Edi997Details与EdiDocType和EdiTransactionDetails没有关系。我能够检索除Edi997Details之外的所有内容。
以下是在EdiTransactionRepository中检索EdiTransaction的代码:
public function getAsnDetails ($poNumber,$fileName, $page = 1 , $limit = 15) {
$em = $this->getEntityManager();
$query = $em->createQuery(
'SELECT partial a.{ediTransactionDetailId, poNumber},
partial b.{ediTransactionId, senderId, receiverId, gsNumber, isaNumber, fileName, transactionDate},
partial c.{ediDocTypeId, docType}
FROM MatrixEdiBundle:EdiTransactionDetail a
JOIN a.ediTransaction b
JOIN b.ediDocType c
WHERE b.fileName LIKE :fileName
AND a.poNumber LIKE :poNumber
AND c.docType = :doc_type
AND a.flag = 1 AND b.flag = 1
ORDER BY b.transactionDate desc')
->setParameter('poNumber', "%$poNumber%")
->setParameter('fileName', "%$fileName%")
->setParameter('doc_type', 856)
->setFirstResult(($page - 1) * $limit)
->setMaxResults($limit);
$paginator = new Paginator ($query , $fetchJoinCollection = false );
$paginator->setUseOutputWalkers(false);
return $paginator;
}
这是针对Edi997详细信息:
public function getAsnStatus(){
$em = $this->getEntityManager();
$query = $em->createQuery(
'SELECT partial a.{id, ak301, ak401},
partial b.{errorCode, condition},
partial c.{edi997DetailId, errorCodeId, noOfTrans, acceptedTrans},
partial d.{ediTransactionId, senderId, receiverId, gsNumber, isaNumber, fileName}
FROM MatrixEdiBundle:Edi997SegmentInError a
JOIN a.ediAk403ErrorCodes b
JOIN a.edi997Details c
JOIN c.ediTransaction d
WHERE c.errorCodeId != 0
AND d.flag = 1');
return $query->getResult();
}
有没有办法加入Edi997Details和EdiTransaction表,DocType和EdiTransactionDetail不会受到影响?我需要一些关于如何解决这个问题的帮助和想法。我是初学者,也是我第一次访问这个网站。
答案 0 :(得分:0)
试试这个:
table1 -> table2,table3
table3 -> table1,table2
table4 -> table2
select a.column,b.column,c.column,d from table1 a join table2 b join
table3 join table4 d on d.column=b.column where...
答案 1 :(得分:0)
这个命名对我没有意义,无论如何我会尝试让你感到困惑的关系:
Edi997< - ediTransaction - > ediDocType
由于学说是面向对象的,你可以做Edi997 - > GetEdiTransactions吗?它在查询中是相同的
$qb = $em->createQueryBuilder("Edi997"); //or other entity, it is for test purpose
$qb
// [...]
->innerJoin("Edi997.ediTransactions","ediTransaction")
->innerJoin("ediTransaction.ediDocType","ediDocType")
// [...]
->andWhere("ediDocType.attribute = :aParameter")
;