8000 feature #143 Replace query builder with DQL (bocharsky-bw) · symfony/demo@d8c53bb · GitHub
[go: up one dir, main page]

Skip to content

Commit d8c53bb

Browse files
committed
feature #143 Replace query builder with DQL (bocharsky-bw)
This PR was merged into the master branch. Discussion ---------- Replace query builder with DQL The `select` and `from` methods are optional Commits ------- 83e5b9a Replace query builder with DQL
2 parents 7075c81 + 83e5b9a commit d8c53bb

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/AppBundle/Repository/PostRepository.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@ class PostRepository extends EntityRepository
2626
{
2727
public function findLatest($limit = Post::NUM_ITEMS)
2828
{
29-
return $this
30-
->createQueryBuilder('p')
31-
->select('p')
32-
->where('p.publishedAt <= :now')->setParameter('now', new \DateTime())
33-
->orderBy('p.publishedAt', 'DESC')
29+
return $this->getEntityManager()
30+
->createQuery('
31+
SELECT p
32+
FROM AppBundle:Post p
33+
WHERE p.publishedAt <= :now
34+
ORDER BY p.publishedAt DESC
35+
')
36+
->setParameter('now', new \DateTime())
3437
->setMaxResults($limit)
35-
->getQuery()
3638
->getResult()
3739
;
3840
}

0 commit comments

Comments
 (0)
0