0

尝试使用 Doctrine Query Builder 查询数据库(它适用于 Symfony2 表单,因此必须使用查询构建器)。

收到以下错误:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'c2_.caseFileID' in 'on clause'

我的查询如下:

$er->createQueryBuilder('ia')  
   ->select( 'ia' )  
   ->from( 'TheBundle:CaseInstruction', 'ci' )  
   ->innerJoin( 'TheBundle:CaseFile', 'cf', 'WITH', 'ci.caseFile = cf' )  
   ->innerJoin( 'TheBundle:Workflow', 'wf', 'WITH', 'wf.product = ci.product AND wf.company = cf.company' )  
   ->innerJoin( 'TheBundle:WorkflowInstructionAction', 'wfia', 'WITH', 'wfia.instructionAction = ia AND wfia.workflow = wf' )  
   ->innerJoin( 'TheBundle:Process', 'p', 'WITH', 'p.currentStatus = ci.status AND p.workflow = wf' )  
   ->innerJoin( 'TheBundle:ProcessTrigger', 'pt', 'WITH', 'pt.instructionAction = ia AND pt.process = pt' )  
   ->where( 'ci.id = :cid' )  
   ->andWhere( 'ia.isSystemAction = :isSystemAction' )  
   ->setParameter( 'isSystemAction', '0' )  
   ->setParameter( 'cid', $options['caseInstructionId'] );

其计算结果为以下教义查询(如异常所示):

'SELECT i0_.id AS id0,
        i0_.codeName AS codeName1,
        i0_.permissions AS permissions2,
        i0_.description AS description3,
        i0_.isSystemAction AS isSystemAction4,
        i0_.instructionActivityID AS instructionActivityID5,
        i0_.instructionSubjectID AS instructionSubjectID6 
 FROM InstructionAction i0_
     INNER JOIN CaseFile c1_ ON (c2_.caseFileID = c1_.id)
     INNER JOIN Workflow w3_ ON (w3_.productID = c2_.productID AND w3_.companyID = c1_.companyID) 
     INNER JOIN WorkflowInstructionAction w4_ ON (w4_.instructionActionID = i0_.id AND w4_.workflowID = w3_.id)
     INNER JOIN Process p5_ ON (p5_.currentStatusID = c2_.instructionStatusID AND p5_.workflowID = w3_.id) 
     INNER JOIN ProcessTrigger p6_ ON (p6_.instructionActionID = i0_.id AND p6_.processID = p6_.id), CaseInstruction c2_ 
 WHERE c2_.id = ? 
 AND i0_.isSystemAction = ?' with params ["307", "0"]

(试图使其尽可能可读)

有谁知道如何解决这个错误?我有本机 SQL 版本工作,实际上我只是想将它翻译成 Doctrine Query Builder。

编辑:工作 SQL:

SELECT ia.* FROM (InstructionAction ia, CaseInstruction ci)
JOIN CaseFile cf ON ci.caseFileID=cf.id
JOIN Workflow wf ON ci.productID=wf.productID AND wf.companyID = cf.companyID
JOIN WorkflowInstructionAction wia ON wia.workflowID=wf.id AND wia.instructionActionID = ia.id
JOIN Process p ON p.currentStatusID = ci.instructionStatusID AND p.workflowID = wf.id
JOIN ProcessTrigger pt ON pt.instructionActionID = ia.id AND pt.processID = p.id

WHERE ci.id = 275
AND ia.isSystemAction=0;

CaseInstruction ID275只是一个示例 CaseInstruction ID -$options['caseInstructionID']在 Query Builder 中被替换。

4

0 回答 0