Doctrine 选择的连接对象

Doctrine selected joined objects

我有两个两个相关的条目(class): 首先class(待办class):

class Todo
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;
}

和评论 class(部分):

class Comment
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * ID человека
     * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Todo")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="postid", referencedColumnName="id")
     * })
     */
    private $postId;
}

我如何 select 通过 Todo id 发表评论?

在控制器中我尝试:

$todos=$this->getDoctrine()
    ->getRepository('AppBundle:Todo')
    ->find($id);
//   var_dump($todos);
$em=$this->getDoctrine()->getManager();
$comments=$em->createQueryBuilder()
    ->select('c')
    ->from('Comment','c')
    ->leftJoin('')
    ->where('postid',':postID')
    ->orderBy('postid', 'ASC')
     ->setParameter('postID', $id)
     ->getQuery()
     ->getResult();

如何选择评论与Todo的连接?

也许这些更改会如您所愿:

class Comment
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * ID человека
     * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Todo")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="postid", referencedColumnName="id")
     * })
     */
    private $post;
}

和...

$todos = $this->getDoctrine()
    ->getRepository('AppBundle:Todo')
    ->find($id);

$em = $this->getDoctrine()->getManager();
$comments = $em->createQueryBuilder()
    ->select('c')
    ->from('Comment', 'c')
    ->leftJoin('AppBundle:Todo', 't')
    ->where('c.post = :todo')
    ->orderBy('post', 'ASC')
    ->setParameter('todo', $todos)
    ->getQuery()
    ->getResult();