title: Symfony2 filter related entities in controller
body: <p>I have an entity "Note", that links to my entity "User" in a ManyToMany Relationship. From my User entity, I want to get all Notes that match certain criteria.</p>
  
  <p>I know the via ORM you can do this: </p>
  
  <pre><code>$this-&gt;getDoctrine()-&gt;getRepository('PmbLicensingBundle:Note')-&gt;findBy(array('criteria' =&gt; $value));
  </code></pre>
  
  <p>Is the same thing possible by invoking a method on an entity, for instance:</p>
  
  <pre><code>$this-&gt;getUser()-&gt;getSharedNotes(array('criteria' =&gt; $value));
  </code></pre>
  
  <p>Alternatively, is there a way to use the former ORM command to filter within a ManyToMany relationship, for instance:</p>
  
  <pre><code>$this-&gt;getDoctrine()-&gt;getRepository('PmbLicensingBundle:Note')-&gt;findBy(array('criteria' =&gt; $value, sharedUsers CONTAINS $this-&gt;getUser()));
  </code></pre>
  
  <p>Excerpt from Entity User.php:</p>
  
  <pre><code>/**
   * User
   *
   * @ORM\Entity
   * @ORM\Table(name="users")
   * @Ser\ExclusionPolicy("all")
   */
  class User implements AdvancedUserInterface, \Serializable
  {
      /**
       * @var integer
       *
       * @ORM\Column(name="id", type="integer")
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="AUTO")
       * @Ser\Expose
       */
      protected $id;
  
      /**
        * @var User[]
        * 
        * @ORM\ManyToMany(targetEntity="Pmb\LicensingBundle\Entity\User", inversedBy="sharedNotes")
        * @Ser\Expose
       **/
      protected $sharedUsers;
  
      ...
  }
  </code></pre>
  
  <p>Excerpt from Entity User.php</p>
  
  <pre><code>/**
   * User
   *
   * @ORM\Entity
   * @ORM\Table(name="users")
   * @Ser\ExclusionPolicy("all")
   */
  class User implements AdvancedUserInterface, \Serializable
  {
      /**
       * @var integer
       *
       * @ORM\Column(name="id", type="integer")
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="AUTO")
       * @Ser\Expose
       */
      protected $id;
  
  
      /**
        * @var Note[]
        * 
        * @ORM\ManyToMany(targetEntity="Pmb\LicensingBundle\Entity\Note", mappedBy="sharedUsers")
        * @Ser\Expose
       **/
      protected $sharedNotes;
  
      ...
  }
  </code></pre>
  
  <p>Alternatively, what is the recommended solution matching criteria on a ManyToMany or OneToMany property? I would prefer to execute this without relying on an Entity Manager.</p>