title: custom query in entity field type
body: <p>I build a form with entity type like this:</p>
  
  <pre><code>$form = $this-&gt;createFormBuilder()
  -&gt;add('users', 'entity', array(
      'class' =&gt; 'UserBundle:Users',
          'query_builder' =&gt; function(EntityRepository $er) {
              return $er-&gt;createQueryBuilder('u')
                            -&gt;orderBy('u.name', 'ASC');
                          },)
        )
  -&gt;getForm();
  </code></pre>
  
  <p>Now I want to modify this form, to show only distinct users. I try this:</p>
  
  <pre><code>-&gt;add('users', 'entity', array(
                          'class' =&gt; 'UserBundle:Users',
                          'query_builder' =&gt; function(EntityRepository $er) {
                          return $er-&gt;createQuery('SELECT DISTINCT u.name FROM UserBundle:Users ORDER BY u.name ASC')-&gt;getResult();
                          },)
                        )
  </code></pre>
  
  <p>but Symfony throws me an exception. My question is how can I use custom query in entity field type?</p>
  
  <hr>
  
  <p>I don't understand what you mean with last answer. My code looks like:</p>
  
  <p>repository:</p>
  
  <pre><code>public function getDistinctUsers()
  {
      return $this-&gt;getEntityManager()-&gt;createQuery('SELECT DISTINCT u.name FROM UserBundle:Users u ORDER BY u.name DESC')-&gt;getResult();
  }
  </code></pre>
  
  <p>controller:</p>
  
  <pre><code>-&gt;add('users', 'entity', array(
      'class' =&gt; 'UserBundle:Users',
      'query_builder' =&gt; function(EntityRepository $er) {
              return $er-&gt;getDistinctUsers();
           },)
        )
  </code></pre>
  
  <p>twig:</p>
  
  <pre><code>&lt;form action="{{ path('user') }}" method="post" {{ form_enctype(form) }}&gt;
      {{ form_widget(form) }}
      &lt;input type="submit" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>and it throws an exception: An exception has been thrown during the rendering of a template ("Expected argument of type "Doctrine\ORM\QueryBuilder", "array" given") ...</p>