title: Symfony2 entity field type alternatives to "property" or "__toString()"?
body: <p>Using Symfony2 <a href="http://symfony.com/doc/current/reference/forms/types/entity.html" rel="noreferrer">entity field type</a> one should specify <code>property</code> option: </p>
  
  <pre><code>$builder-&gt;add('customers', 'entity', array(
      'multiple' =&gt; true,
      'class'    =&gt; 'AcmeHelloBundle:Customer',
      'property' =&gt; 'first',
  ));
  </code></pre>
  
  <p>But sometimes this is not sufficient: think about two customers with the same name, so display the email (unique) would be mandatory.</p>
  
  <p>Another possibility is to implement <code>__toString()</code> into the model:</p>
  
  <pre><code>class Customer
  {
      public $first, $last, $email;
  
      public function __toString()
      {
          return sprintf('%s %s (%s)', $this-&gt;first, $this-&gt;last, $this-&gt;email);
      }
  }
  </code></pre>
  
  <p>The disadvances of the latter is that you are <strong>forced to display the entity the same way</strong> in all your forms.</p>
  
  <p><strong><em>Is there any other way to make this more flexible?</em></strong> I mean something like a callback function:</p>
  
  <pre><code>$builder-&gt;add('customers', 'entity', array(
      'multiple' =&gt; true,
      'class'    =&gt; 'AcmeHelloBundle:Customer',
      'property' =&gt; function($data) {
           return sprintf('%s %s (%s)', $data-&gt;first, $data-&gt;last, $data-&gt;email);
       },
  ));
  </code></pre>