Browse Source

On réduit les requêtes

François 6 years ago
parent
commit
07bc5ab748

+ 2 - 1
src/AppBundle/Controller/VideothequeController.php

@@ -30,7 +30,8 @@ class VideothequeController extends Controller
 	{
 		$em = $this->getDoctrine()->getManager();
 		$repo = $em->getRepository('AppBundle:Film');
-		$listeFilms = $repo->findAll();
+		//$listeFilms = $repo->findAll();
+        $listeFilms = $repo->findTous();
 
 		return $this->render('@App/videotheque/liste.html.twig', array(
 			'listeFilms'	=>	$listeFilms

+ 11 - 0
src/AppBundle/Repository/FilmRepository.php

@@ -86,4 +86,15 @@ class FilmRepository extends \Doctrine\ORM\EntityRepository
             ->getQuery()
             ->getResult();
     }
+
+    public function findTous () {
+        $qb = $this->createQueryBuilder('f')
+            ->leftJoin('f.authered', 'aut')->addSelect('aut')
+            ->leftJoin('f.genres', 'gen')->addSelect('gen')
+            ->leftJoin('f.realisateurs', 'rea')->addSelect('rea');
+
+        return $qb
+            ->getQuery()
+            ->getResult();
+    }
 }