title: Symfony2 doctrine passing a parameter on foreign key in findBy function
body: <p>i'm trying to load an entity passing a parameter to a foreign key which is the <code>inverse side</code></p>
  
  <p>i have this two entities</p>
  
  <p>Ad</p>
  
  <pre><code>/**
   * Ad
   *
   * @ORM\Table(name="Ad")
   * @ORM\Entity(repositoryClass="Symarket\MarketBundle\Repository\AdRepository")
   */
  class Ad 
  {
       /**
       * @var AdImage
       *
       * @ORM\OneToMany(targetEntity="AdImage", mappedBy="ad", cascade={"persist", "merge"})
       */
       private $images;
  
       //...
  }
  </code></pre>
  
  <p>AdImage</p>
  
  <pre><code>/**
   * AdImage
   *
   * @ORM\Table(name="AdImage")
   * @ORM\Entity(repositoryClass="Symarket\MarketBundle\Repository\AdImageRepository")
   */
  class AdImage {
  
      /**
       * @var boolean
       *
       * @ORM\Column(name="adi_is_visible", type="boolean")
       */
      protected $isVisible;
  
      /**
       * @var Ad
       *
       * @ORM\ManyToOne(targetEntity="Ad", inversedBy="images", cascade={"persist"})
       * @ORM\JoinColumn(name="adi_ad_id", referencedColumnName="ad_id")
       */
      protected $ad;
  }
  </code></pre>
  
  <p>now, by getting a <code>Ad</code> from the database i want to get ONLY the images which are <code>"isVisibile" =&gt; true</code></p>
  
  <p>how is this possible with queryBuilder?</p>
  
  <p>what i tried so far with the findBy function is this</p>
  
  <pre><code>public function findById($adId) {
      $res = $this-&gt;findBy(array("id" =&gt; $adId, "isVisible" =&gt; true, "images" =&gt; array("isVisible" =&gt; true)));
      $ad = reset($res);
  
      return $ad;
  }
  </code></pre>
  
  <p>and i got this error
      You cannot search for the association field 'Symarket\MarketBundle\Entity\Ad#images', because it is the inverse side of an association. Find methods only work on owning side associations.</p>
  
  <p>then i tried this way with the querybuilder</p>
  
  <pre><code>public function findById($adId) {
      $res = $query = $this-&gt;createQueryBuilder('ad')
              -&gt;leftJoin('ad.images', 'img')
              -&gt;where('img.isVisible = :adVisible')
              -&gt;andWhere('ad.id = :id')
              -&gt;setParameter('adId', $adId)
              -&gt;setParameter('imgVisible', true)
              -&gt;getQuery();
  
      $ad = reset($res);
  
      return $ad;
  }
  </code></pre>
  
  <p>and i get <code>NULL</code></p>
  
  <p>Thanks in advance.</p>