title: Symfony2 form choice field
body: <p>I have a <code>Product</code> and a <code>Category</code> entity.</p>
  
  <p><code>Category</code> entity is a adjacency list/materialized-path model.</p>
  
  <p><code>Product</code> has a relation to <code>Category</code> which has a relation back to <code>Product</code></p>
  
  <p>In my <code>ProductType</code> class I would like a selectmenu with all categories at a specific level grouped by parent name.</p>
  
  <pre><code>$builder-&gt;add('category', 'entity', array(
              'label'    =&gt; 'Category',
              'class'    =&gt; 'Test\AdminBundle\Entity\Category',
              'property' =&gt; 'name',
              'group_by' =&gt; 'parentName',
              'query_builder' =&gt; function(\Doctrine\ORM\EntityRepository $er) {
  
                  $qb = $er-&gt;createQueryBuilder('c');
  
                  return $qb-&gt;where($qb-&gt;expr()-&gt;like('c.path', ':path'))
                          -&gt;orderBy('c.path', 'ASC')
                          -&gt;setParameter('path', '%/%/%');
              },
      ));
  </code></pre>
  
  <p><code>Category</code> got a <code>getParentName</code> method:</p>
  
  <pre><code>public function getParentName()
  {
      if (null === $this-&gt;getParent()) {
      return null;
      }
  
      return $this-&gt;getParent()-&gt;getName();
  }
  </code></pre>
  
  <p>It works as expected but a query is executed for every parent (a lot). If I make a join with parent the parent will also be selectable in the selectmenu which I don't want.</p>
  
  <p>How do I limit the queries?</p>
  
  <p>Or filter a joined result?</p>