Symfony2-列出按描述顺序从Post实体排序的注释

Symfony2-列出按描述顺序从Post实体排序的注释,symfony,post,doctrine-orm,comments,Symfony,Post,Doctrine Orm,Comments,我的评论设置为多个帖子 我想以DESC顺序显示帖子中的所有评论 我已经设置了一个查询来列出一篇带有描述顺序的文章,但是评论仍然显示为ASC 我如何获得按描述顺序显示的注释?它不是继承了帖子列表的方式吗? 查询后 public function findPostsBySlug($slug) { return $this->createQueryBuilder('post') ->select('post') ->where('post.sl

我的评论设置为多个帖子

我想以DESC顺序显示帖子中的所有评论

我已经设置了一个查询来列出一篇带有描述顺序的文章,但是评论仍然显示为ASC

我如何获得按描述顺序显示的注释?它不是继承了帖子列表的方式吗?

查询后

public function findPostsBySlug($slug)
{
    return $this->createQueryBuilder('post')
        ->select('post')
        ->where('post.slug = :slug')
        ->setParameter('slug', $slug)
        ->orderBy('post.createdAt', 'DESC')
        ->getQuery()
        ->getSingleResult();
}
小枝


好的,我明白了,我需要对注释进行另一个查询,并在控制器中调用它

public function findCommentsForPost($postId)
{
    return $this->createQueryBuilder('comment')
        ->select('comment')
        ->where('comment.post = :post_id')
        ->setParameter('post_id', $postId)
        ->orderBy('comment.createdAt', 'DESC')
        ->getQuery()
        ->getResult();
}
public function showAction($slug)
{
    $post = $this->getDoctrine()->getRepository('AcmeDemoBundle:Post')
        ->findPostsBySlug($slug);

    if (null === $post) {
        throw $this->createNotFoundException('Post was not found');
    }

    return array(
        'post' => $post
    );
}
public function findCommentsForPost($postId)
{
    return $this->createQueryBuilder('comment')
        ->select('comment')
        ->where('comment.post = :post_id')
        ->setParameter('post_id', $postId)
        ->orderBy('comment.createdAt', 'DESC')
        ->getQuery()
        ->getResult();
}