Skip to content

Instantly share code, notes, and snippets.

@haswalt
Created December 2, 2011 10:57
Show Gist options
  • Select an option

  • Save haswalt/1422794 to your computer and use it in GitHub Desktop.

Select an option

Save haswalt/1422794 to your computer and use it in GitHub Desktop.
{% for competition in competitions %}
<tr>
<td>{{ competition.title }}</td>
<td>{{ competition.searchPhrase }}</td>
<td>{{ competition.openAt|date }}</td>
<td>{{ competition.closeAt|date }}</td>
<td>{{ competition.total }}</td>
</tr>
{% endfor %}
<?php
use Doctrine\ORM\EntityRepository;
/**
* CompetitionRepository
*
* This class was generated by the Doctrine ORM. Add your own custom
* repository methods below.
*/
class CompetitionRepository extends EntityRepository
{
public function findAllWithCount()
{
$qb = $this->createQueryBuilder('c');
$qb->select('c.id, c.title, c.searchPhrase, c.openAt, c.closeAt, COUNT(e.competition) AS total, c.winnerId')
->leftJoin('c.entries', 'e')
->groupBy('c.id, c.title, c.searchPhrase, c.openAt, c.closeAt, c.winnerId, e.competition')
->orderBy('c.openAt');
return $qb->getQuery()->getArrayResult();
}
@haswalt

haswalt commented Jun 14, 2012

Copy link
Copy Markdown
Author

Test comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment