title: Select entities where referenced objects property is equals value
body: <p>Right now i try to wrap my head around Doctrine2.</p>
  
  <p>So i have the following structure:</p>
  
  <p>I have an article entity:</p>
  
  <pre><code>/**
   * @ORM\Entity
   * @ORM\HasLifecycleCallbacks
   * @ORM\Table(name="article")
   */
  class Article extends BaseEntity {
  
      /**
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="AUTO")
       * @ORM\Column(type="integer")
       */
      protected $id;
  
      /**
       * @ORM\OneToMany(targetEntity="ArticleRevision", mappedBy="article", cascade={"persist"})
       * @var ArrayCollection
       */
      private $articleRevisions;
  
      /**
       * @ORM\ManyToOne(targetEntity="ArticleRevision")
       * @ORM\JoinColumn(name="currentRevisionId", referencedColumnName="id", nullable=true)
       * @var ArticleRevision
       */
      private $currentRevision;
  
      public function __construct(array $options = null) {
          $this-&gt;articleRevisions = new ArrayCollection();
          parent::__construct($options);
      }
  
      /**
       * @return int
       */
      public function getId() {
          return $this-&gt;id;
      }
      /**
       * @param int $id
       */
      public function setId($id) {
          $this-&gt;id = $id;
      }
  
      /**
       * @param ArticleRevision $articleRevision
       */
      public function addArticleRevision($articleRevision) {
          $this-&gt;articleRevisions[] = $articleRevision;
          $articleRevision-&gt;setArticle($this);
      }
  
      /**
       * @return ArrayCollection
       */
      public function getArticleRevisions() {
          return $this-&gt;articleRevisions;
      }
  
      /**
       * @return ArticleRevision
       */
      public function getCurrentRevision() {
          return $this-&gt;currentRevision;
      }
      /**
       * @param ArticleRevision $articleRevision
       */
      public function setCurrentRevision($articleRevision) {
          $this-&gt;currentRevision = $articleRevision;
      }
  }
  </code></pre>
  
  <p>that has articleRevisions and references its current revision:</p>
  
  <pre><code>/**
   * @ORM\Entity
   * @ORM\HasLifecycleCallbacks
   * @ORM\Table(name="articlerevision")
   */
  class ArticleRevision extends BaseEntity {
  
      const TYPE_RELEASE = "release";
      const TYPE_DRAFT = "draft";
      const TYPE_AUTOSAVE = "autosave";
  
      /**
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="AUTO")
       * @ORM\Column(type="integer")
       * @var int
       */
      protected $id;
  
      /**
       * @ORM\ManyToOne(targetEntity="Category")
       * @ORM\JoinColumn(name="categoryId", referencedColumnName="id")
       * @var Category
       **/
      private $category;
  
      /**
       * @ORM\ManyToOne(targetEntity="Article", inversedBy="articleRevisions")
       * @ORM\JoinColumn(name="articleId", referencedColumnName="id")
       * @var Article
       **/
      private $article;
  
      /**
       * @ORM\Column(type="string")
       * @var string
       */
      protected $urlParam;
  
      /**
       * @ORM\Column(type="string")
       * @var string
       */
      protected $copyright;
  
      /**
       * @ORM\Column(type="string")
       * @var string
       */
      protected $supertitle;
  
      /**
       * @ORM\Column(type="string")
       * @var string
       */
      protected $title;
  
      /**
       * @ORM\Column(type="text")
       * @var string
       */
      protected $teaser;
  
      /**
       * @ORM\Column(type="text")
       * @var string
       */
      protected $text;
  
      /**
       * @ORM\ManyToOne(targetEntity="ArticleRevision")
       * @ORM\JoinColumn(name="previousRevisionId", referencedColumnName="id", nullable=true)
       * @var ArticleRevision
       */
      private $previousRevision;
  
      public function __construct(array $options = null) {
          parent::__construct($options);
      }
  
      /**
       * @return int
       */
      public function getId() {
          return $this-&gt;id;
      }
      /**
       * @param int $id
       */
      public function setId($id) {
          $this-&gt;id = $id;
      }
  
      /**
       * @return Category
       */
      public function getCategory() {
          return $this-&gt;category;
      }
      /**
       * @param Category $category
       */
      public function setCategory($category){
          $this-&gt;category = $category;
      }
  
      /**
       * @return Article
       */
      public function getArticle() {
          return $this-&gt;article;
      }
      /**
       * @param Article $article
       */
      public function setArticle($article) {
          $this-&gt;article = $article;
      }
  
      /**
       * @return string
       */
      public function getCopyright() {
          return $this-&gt;copyright;
      }
      /**
       * @param string $copyright
       */
      public function setCopyright($copyright) {
          $this-&gt;copyright = $copyright;
      }
  
      /**
       * @return string
       */
      public function getUrlParam() {
          return $this-&gt;urlParam;
      }
      /**
       * @param string $urlParam
       */
      public function setUrlParam($urlParam) {
          $this-&gt;urlParam = $urlParam;
      }
  
      /**
       * @return string
       */
      public function getSupertitle() {
          return $this-&gt;supertitle;
      }
      /**
       * @param string $supertitle
       */
      public function setSupertitle($supertitle) {
          $this-&gt;supertitle = $supertitle;
      }
  
      /**
       * @return string
       */
      public function getTitle() {
          return $this-&gt;title;
      }
  
      /**
       * @param string $title
       */
      public function setTitle($title) {
          $this-&gt;title = $title;
      }
  
      /**
       * @return string
       */
      public function getTeaser() {
          return $this-&gt;teaser;
      }
      /**
       * @param string $teaser
       */
      public function setTeaser($teaser) {
          $this-&gt;teaser = $teaser;
      }
  
      /**
       * @return string
       */
      public function getText() {
          return $this-&gt;text;
      }
      /**
       * @param string $text
       */
      public function setText($text) {
          $this-&gt;text = $text;
      }
  
      /**
       * @return ArticleRevision
       */
      public function getPreviousRevision() {
          return $this-&gt;previousRevision;
      }
      /**
       * @param ArticleRevision $previousRevision
       */
      public function setPreviousRevision($previousRevision) {
          $this-&gt;previousRevision = $previousRevision;
      }
  } 
  </code></pre>
  
  <p>What i am trying to achieve is to select every article, where the categoryId of the currentRevision is for example 1.</p>
  
  <p>I've tried: </p>
  
  <pre><code>$qb = $this-&gt;getRepository()-&gt;createQueryBuilder('a');
  $qb-&gt;leftJoin('a.currentRevision', 'r')
     -&gt;where('r.category = :category')
     -&gt;setParameters(array('category' =&gt; $category));
  return $qb-&gt;getQuery()-&gt;getResult();
  </code></pre>
  
  <p>Where <code>$category</code> is an int or the <code>Application\Entity\Category</code>. Both is returning an empty array. Can you point me in the right direction?</p>
  
  <p>Any help is appreciated!</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Ouput of <code>$qb-&gt;__toString()</code>:</p>
  
  <blockquote>
    <p>SELECT a FROM Application\Entity\Article a LEFT JOIN a.currentRevision
    r WHERE r.category = :category</p>
  </blockquote>