Skip to content

Instantly share code, notes, and snippets.

@gdarquie
Last active January 30, 2020 10:21
Show Gist options
  • Save gdarquie/27f41af426c6f8396f402d0cc7a47c6b to your computer and use it in GitHub Desktop.
Save gdarquie/27f41af426c6f8396f402d0cc7a47c6b to your computer and use it in GitHub Desktop.
public function findAllDistinctFragments(int $limit)
{
$sql = "SELECT DISTINCT ON (f.code) * FROM fragment f ORDER BY f.code, f.created_at DESC ";
$rsm = new ResultSetMappingBuilder($this->getEntityManager());
$rsm->addRootEntityFromClassMetadata(Fragment::class, 'f');
$query = $this->getEntityManager()->createNativeQuery($sql, $rsm);
return $query->getResult();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment