Skip to content

Commit

Permalink
Merge pull request #985 from tomudding/hotfix/missing-organ-members
Browse files Browse the repository at this point in the history
Fix missing members when getting 'latest' organ
  • Loading branch information
Koen1999 authored Feb 10, 2020
2 parents f2eeceb + 360e8f9 commit c9cd9d3
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions module/Decision/src/Decision/Mapper/Organ.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function find($id)
*
* It is possible that multiple organs with the same abbreviation exist,
* for example, through the reinstatement of an previously abrogated organ.
* To retrieve the latest occurence of such an organ use `$latest`.
* To retrieve the latest occurence of such an organ use `$latest`.
*
* @param string $abbr
* @param string $type
Expand All @@ -122,17 +122,24 @@ public function findByAbbr($abbr, $type = null, $latest = false)
$qb->select('o, om, m')
->leftJoin('o.members', 'om')
->leftJoin('om.member', 'm')
->where('o.abbr = :abbr');
->where('o.abbr = :abbr')
->setParameter('abbr', $abbr);
if (!is_null($type)) {
$qb->andWhere('o.type = :type')
->setParameter('type', $type);
}
if ($latest) {
$qb->orderBy('o.foundationDate', 'DESC')
->setMaxResults(1);
}
$qb->orderBy('o.foundationDate', 'DESC');
$queryResult = $qb->getQuery()->getResult();

if (count($queryResult) == 0) {
// the query did not return any records
throw new \Doctrine\ORM\NoResultException('no organ found');
}

$qb->setParameter('abbr', $abbr);
// the query returned at least 1 record, use first (= latest) record
return $queryResult[0];
}

return $qb->getQuery()->getSingleResult();
}
Expand Down

0 comments on commit c9cd9d3

Please sign in to comment.