<?php

namespace SymfonyDay\Bundle\BlogBundle\Entity;

use Doctrine\ORM\EntityRepository;

/**
 * PostRepository
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class PostRepository extends EntityRepository
{
    public function getPublishedPost($id)
    {
        return $this
            ->createQueryBuilder('p')
            ->where('p.id = :id')
            ->andWhere('p.publishedAt IS NULL')
            ->orWhere('p.publishedAt <= :date')
            ->setParameter('id', $id)
            ->setParameter('date', date('Y-m-d H:i'))
            ->getQuery()
            ->getSingleResult()
        ;
    }

    public function getMostRecentPosts()
    {
        return $this
            ->createQueryBuilder('p')
            ->where('p.publishedAt IS NULL')
            ->orWhere('p.publishedAt <= :date')
            ->orderBy('p.publishedAt', 'DESC')
            ->setParameter('date', date('Y-m-d H:i'))
            ->getQuery()
            ->execute()
        ;
    }
}
<?php

namespace SymfonyDay\Bundle\BlogBundle\Entity;

use Doctrine\ORM\EntityRepository;

/**
 * PostRepository
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class PostRepository extends EntityRepository
{
    public function getPublishedPost($id)
    {
        return $this
            ->createQueryBuilder('p')
            ->where('p.id = :id')
            ->andWhere('p.publishedAt IS NULL OR p.publishedAt <= :date')
            ->setParameter('id', $id)
            ->setParameter('date', date('Y-m-d H:i'))
            ->getQuery()
            ->getSingleResult()
        ;
    }

    public function getMostRecentPosts()
    {
        return $this
            ->createQueryBuilder('p')
            ->where('p.publishedAt IS NULL')
            ->orWhere('p.publishedAt <= :date')
            ->orderBy('p.publishedAt', 'DESC')
            ->setParameter('date', date('Y-m-d H:i'))
            ->getQuery()
            ->execute()
        ;
    }
}
Fix where clause in getPublishedPost
Fix where clause in getPublishedPost
