简体   繁体   English

如何从Doctrine和Symfony获得标量结果的总和?

[英]How to get an aggregate scalar result from Doctrine and Symfony?

How do I get Person, Application, Scalar A as a result set? 如何获得人,应用程序,标量A的结果集?

I am currently getting an array with [0] => Person [1] => Application etc. The 'addScalarResult()' call seems to be getting ignored. 我当前正在使用[0] => Person [1] => Application等获取数组。“ addScalarResult()”调用似乎被忽略了。

public function exportHR63Status(Semester $semester) {
  $resultSetMapping = new ResultSetMappingBuilder($this->getEntityManager());
  $resultSetMapping->addRootEntityFromClassMetadata('Unsw\CamsBundle\Entity\Person', 'p');
  $resultSetMapping->addRootEntityFromClassMetadata('Unsw\CamsBundle\Entity\Application', 'a',
  array(
    'id' => 'application_id',
    'deleted' => 'application_deleted',
    'created' => 'application_created',
    'updated' => 'application_updated'
  ));

  $selectClause = $resultSetMapping->generateSelectClause();

  $resultSetMapping->addScalarResult('signedCasual', 'signedCasual');
  $resultSetMapping->addScalarResult('signedFinance', 'signedFinance');
  $resultSetMapping->addScalarResult('signedHeadOfSchool', 'signedHeadOfSchool');

  $q = $this->getEntityManager()->createNativeQuery("SELECT " . $selectClause . ",
    EXISTS (select 1 from hr63signer_hr63submission hshs INNER JOIN hr63signer hs ON hshs.hr63signer_id = hs.id WHERE h1_.id = hshs.hr63submission_id and hs.signertype = 'casual') as signedCasual,
    EXISTS (select 1 from hr63signer_hr63submission hshs INNER JOIN hr63signer hs ON hshs.hr63signer_id = hs.id WHERE h1_.id = hshs.hr63submission_id and hs.signertype = 'finance') as signedFinance,
    EXISTS (select 1 from hr63signer_hr63submission hshs INNER JOIN hr63signer hs ON hshs.hr63signer_id = hs.id WHERE h1_.id = hshs.hr63submission_id and hs.signertype = 'headofschool') as signedHeadOfSchool
    -- processed finance is hr63_submission.processed_finance
    FROM hr63_submission h1_
    INNER JOIN course c2_ ON h1_.course_id = c2_.id
    INNER JOIN application_courses ac ON c2_.id = ac.course_id
    INNER JOIN application a ON ac.application_id = a.id
    INNER JOIN person p ON h1_.person_id = p.znumber
    WHERE c2_.semester_id = 14 -- either course or application should give the same result", $resultSetMapping);

  $q->setParameter('semester_id', $semester->getId());

  return $q->getResult();
}

Symfony 2.7.6, Doctrine 2.5.1 Symfony 2.7.6,Doctrine 2.5.1

The answer is that I had the parameter for semester_id hard coded to 14 and bound a parameter that did not match. 答案是我将semester_id的参数硬编码为14,并绑定了一个不匹配的参数。 Change 更改

c2_.semester_id = 14

to

c2_.semester_id = :semester_id

Gives: 给出:

[0] Person
[1] Application plus scalar entries.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何阻止Doctrine 2在Symfony 2中缓存结果? - How to stop Doctrine 2 from caching a result in Symfony 2? 如何获取一维标量数组作为学说dql查询结果? - How to get a one-dimensional scalar array as a doctrine dql query result? 如何遍历symfony(Doctrine)结果对象 - How to iterate through a symfony (Doctrine) result object Symfony 4 学说 sqlsrv 如何从存储过程中获取输出? - Symfony 4 doctrine sqlsrv how to get output from stored procedure? symfony 2.7.4 + doctrine / orm 2.4.8 =无法猜测如何从请求信息中获取Doctrine实例 - symfony 2.7.4 + doctrine/orm 2.4.8 = Unable to guess how to get a Doctrine instance from the request information 在symfony 1.4中使用Doctrine ORM更新mysql表时如何获取结果信息 - How to get result information when updating mysql table with Doctrine ORM in symfony 1.4 如何从doctrine查询生成器获取部分结果 - How to get partial result from doctrine query builder Symfony2与Ajax一起使用,以获取学说中的查询结果 - Symfony2 use with Ajax, to get the result of a query in doctrine 如何在Symfony中以表单类型获取学说存储库? - How to get doctrine repository in form type in Symfony? 如何获取Symfony2中翻译的日期日期时间 - How to get doctrine datetime translated in Symfony2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM