title: Using entity field type in symfony2.1 form
body: <p>Using Symfony 2.1.3-dev and Doctrine 2.3</p>
  
  <p>I am attempting to build a form which provide multiple options for a user to filter a returned set of data (<code>Entity\EngineCodes</code>).  The form is composed of 1 text input field (<code>id</code>) and 3 select fields (<code>module</code>, <code>type</code>, <code>status</code>). I am attempting to use the Symfony2 <code>entity</code> form_type to generate values for the 3 select fields from the <code>EngineCodes</code> entity.</p>
  
  <p>Since I am wanting to filter the table using a combination of any 3 of the select fields. Based on the 2.1 docs, I decided to create a FormType (<code>EngineCodesFilterType</code>) and set three of the form fields to <code>entity</code> type with <code>query_builder</code> statements to return a set of unique values for each of the fields.</p>
  
  <p>Unfortunately, I am receiving the follow error, and I'm not exactly sure why it's returning an array instead of an object.</p>
  
  <pre><code>    The form's view data is expected to be an instance of class
      Vendor\IndexBundle\Entity\EngineCodes, but is a(n) array.
      You can avoid this error by setting the "data_class" option
      to null or by adding a view transformer that transforms a(n)
      array to an instance of Vendor\IndexBundle\Entity\EngineCodes.
  </code></pre>
  
  <p>If I set <code>data_class</code> to <code>null</code>, I receive this error:</p>
  
  <pre><code>    A "__toString()" method was not found on the objects of type
      "Vendor\IndexBundle\Entity\EngineCodes" passed to the choice
      field. To read a custom getter instead, set the option
      "property" to the desired property path.
  </code></pre>
  
  <p>Since I'm still learning these Symfony2 features, my goal was to match the 2.1 docs in terms of construction and format as much as possible.</p>
  
  <p>Here is the function within the Controller:</p>
  
  <pre><code>public function displayAction() {
  
      // ...
  
      $entity = $this-&gt;getDoctrine()-&gt;getEntityManager()
          -&gt;getRepository('VendorIndexBundle:EngineCodes')
          -&gt;findAll();
  
      // ...
  
      $form = $this-&gt;createForm(new EngineCodesFilterType(), $entity);
  
      // ...
  
      return $this-&gt;render(
          'VendorIndexBundle::layout.html.twig',
          array(
              'entity'  =&gt; $entity,
              'form'    =&gt; $form-&gt;createView(),));
  </code></pre>
  
  <p>Here is the form type:</p>
  
  <pre><code>class EngineCodesFilterType extends AbstractType
  {
      public function buildForm(FormBuilderInterface $builder, array $options)
      {
          $builder-&gt;add(
              'id',
              'integer',
              array(
                  'label' =&gt; 'Code ID',));
          $builder-&gt;add(
              'status',
              'entity',
              array(
                  'label' =&gt; 'Code Status',
                  'class' =&gt; 'VendorIndexBundle:EngineCodes',
                  'query_builder' =&gt; function(EntityRepository $er)
                      {
                          return $er-&gt;createQueryBuilder('u')
                              -&gt;select('u.status')
                              -&gt;add('groupBy', 'u.status');
                      },
                  'multiple' =&gt; true,));
          $builder-&gt;add(
              'type',
              'entity',
              array(
                  'label' =&gt; 'Code Type',
                  'class' =&gt; 'VendorIndexBundle:EngineCodes',
                  'query_builder' =&gt; function(EntityRepository $er)
                      {
                          return $er-&gt;createQueryBuilder('u')
                              -&gt;select('u.type')
                              -&gt;add('groupBy' ,'u.type');
                      },
                  'multiple' =&gt; true,));
          $builder-&gt;add(
              'module',
              'entity',
              array(
                  'label' =&gt; 'Code Module',
                  'class' =&gt; 'VendorIndexBundle:EngineCodes',
                  'query_builder' =&gt; function(EntityRepository $er)
                      {
                          return $er-&gt;createQueryBuilder('u')
                              -&gt;select('u.module')
                              -&gt;add('groupBy', 'u.module');
                      },
                  'multiple' =&gt; true,));
      }
  
      public function getName()
      {
          return 'EngineCodesFilter';
      }
  
      public function setDefaultOptions(OptionsResolverInterface $resolver)
      {
          $resolver-&gt;setDefaults(
              array(
                  'data_class'        =&gt; 'Vendor\IndexBundle\Entity\EngineCodes',
                /*'data_class'        =&gt; null,*/
                  'validation_groups' =&gt; 'filter',));
      }
  }
  </code></pre>
  
  <p>And here is the <code>Vendor\Entity\EngineCodes</code> class:</p>
  
  <pre><code>/**
   * Vendor\IndexBundle\Entity\EngineCodes
   *
   * @ORM\Table(name="engine_codes")
   * @ORM\Entity(repositoryClass="Vendor\IndexBundle\Entity\EngineCodesRepository")
   * @UniqueEntity(fields="id", message="ID already in use! Enter a unique ID for the code.")
   */
  class EngineCodes
  {
      /**
       * @var integer $id
       *
       * @ORM\Column(name="id", type="integer", nullable=false, unique=true)
       * @ORM\Id
       * @Assert\NotBlank(message="ID cannot be blank!")
       * @Assert\Regex(pattern="/^\d+$/", match=true, message="ID must be an integer!")
       * @Assert\MinLength(limit=8, message="ID must be 8 numbers in length!")
       * @Assert\MaxLength(limit=8, message="ID must be 8 numbers in length!")
       */
      private $id;
  
      /**
       * @var string $token
       *
       * @ORM\Column(name="token", type="string", length=255, nullable=false, unique=true)
       */
      private $token;
  
      /**
       * @var boolean $status
       *
       * @ORM\Column(name="status", type="integer", nullable=false)
       * @Assert\NotBlank(message="Status cannot be blank!")
       */
      private $status;
  
      /**
       * @var string $module
       *
       * @ORM\Column(name="module", type="string", length=255, nullable=false)
       * @Assert\NotBlank(message="Module cannot be blank!")
       */
      private $module;
  
      /**
       * @var string $submodule
       *
       * @ORM\Column(name="submodule", type="string", length=255, nullable=false)
       * @Assert\NotBlank(message="Submodule cannot be blank!")
       */
      private $submodule;
  
      /**
       * @var string $type
       *
       * @ORM\Column(name="type", type="string", length=255, nullable=false)
       * @Assert\NotBlank(message="Type cannot be blank!")
       */
      private $type;
  
      /**
       * @var string $description
       *
       * @ORM\Column(name="description", type="text", nullable=false)
       * @Assert\NotBlank(message="Description cannot be blank!")
       */
      private $description;
  
      /**
       * @var string $title
       *
       * @ORM\Column(name="title", type="string", length=255, nullable=false)
       * @Assert\NotBlank(message="Title cannot be blank!")
       */
      private $title;
  
      /**
       * @var string $definition
       *
       * @ORM\Column(name="definition", type="text", nullable=true)
       */
      private $definition;
  
      /**
       * @var string $color
       *
       * @ORM\Column(name="color", type="string", length=10, nullable=true)
       */
      private $color;
  
      /**
       * @var \DateTime $createTimestamp
       *
       * @ORM\Column(name="create_timestamp", type="datetime", nullable=false)
       */
      private $createTimestamp;
  
      /**
       * @var Accounts
       *
       * @ORM\ManyToOne(targetEntity="Accounts")
       * @ORM\JoinColumns({
       *   @ORM\JoinColumn(name="create_account_fk", referencedColumnName="id")
       * })
       */
      private $createAccountFk;
  
  
      // getters and setters ...
  
      /**
       * Set createAccountFk
       *
       * @param Vendor\IndexBundle\Entity\Accounts $createAccountFk
       * @return EngineCodes
       */
      public function setCreateAccountFk(\Vendor\IndexBundle\Entity\Accounts $createAccountFk = null)
      {
          $this-&gt;createAccountFk = $createAccountFk;
  
          return $this;
      }
  
      /**
       * @ORM\PrePersist
       */
      public function setCreateTimestampValue()
      {
          $this-&gt;createTimestamp = new \DateTime();
      }
  }
  </code></pre>