Skip to content

Instantly share code, notes, and snippets.

@irwinv
Created June 28, 2012 14:34
Show Gist options
  • Save irwinv/3011703 to your computer and use it in GitHub Desktop.
Save irwinv/3011703 to your computer and use it in GitHub Desktop.
Free Query with getConnection in EntityRepository
<?php
namespace Patrick\ElevageBundle\Repository;
use Doctrine\ORM\EntityRepository;
class ChienRepository extends EntityRepository
{
public function getChiensParRace($chiot, $race){
$conn = $this->_em->getConnection('database_connection');
$sql = "
SELECT *, c.id AS idc FROM Chiens c
LEFT JOIN Images i ON c.id = i.chien_id
WHERE c.chiot = :chiot
&& c.race = :race
GROUP BY i.chien_id
ORDER BY c.nom ASC
";
return $conn->fetchAll($sql, $params = array('chiot' => $chiot, 'race' => $race));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment