title: Error : the new value must be an array or an instance of \Traversable, Entity class given
body: <p>I have a <code>manyToMany</code> association between <code>Post</code> and <code>Category</code>. I am trying to submit the Post form to create a post with the selected category from the dropdown <code>&lt;select&gt;</code>.</p>
  
  <p>Form is rendering correclty using:</p>
  
  <pre><code>&lt;div id="form-categories-widget"&gt;
      &lt;select id="shop_bundle_managementbundle_posttype_categories" 
          name="shop_bundle_managementbundle_posttype[categories]"&gt;
          {% for key,val in form.categories.vars.choices %}
          &lt;option value="{{ val.value }}" {{  form.categories.vars.value == '' and key == 0 ? ' selected ' :(val.value == form.categories.vars.value ? ' selected ' : '') }}
              &gt;
              {{ val.data.getName | trans }} 
          &lt;/option&gt;
          {% endfor %}
      &lt;/select&gt;
  &lt;/div&gt; 
  </code></pre>
  
  <p><strong>The problem:</strong></p>
  
  <p>When I click on submit button I have the following error(for which I have spent about 2 days trying to figure out):</p>
  
  <blockquote>
    <p>The property "categories" in class
    "Shop\Bundle\ManagementBundle\Entity\Post" can be defined with the
    methods "addCategory()", "removeCategory()" but the new value must be
    an array or an instance of \Traversable,
    "Shop\Bundle\ManagementBundle\Entity\Category" given.</p>
  </blockquote>
  
  <p>Here are my form type and entity (if ever they are useful). I thank you in advance for your invaluable time and help as usual.</p>
  
  <p><strong>Entity Post:</strong></p>
  
  <pre><code>&lt;?php
  
  namespace Shop\Bundle\ManagementBundle\Entity;
  
  class Post
  {
  .....
      /**
       * @var \Doctrine\Common\Collections\Collection
       */
      private $categories;
  
  
      /**
       * Add category
       *
       * @param \Shop\Bundle\ManagementBundle\Entity\Category $category
       *
       * @return Post
       */
      public function addCategory(\Shop\Bundle\ManagementBundle\Entity\Category $category)
      {
          $this-&gt;categories[$category-&gt;getName()] = $category;
          $category-&gt;addPost($this);
          return $this;
      }
  
      /**
       * Remove category
       *
       * @param \Shop\Bundle\ManagementBundle\Entity\Category $category
       */
      public function removeCategory(\Shop\Bundle\ManagementBundle\Entity\Category $category)
      {
          $this-&gt;categories-&gt;removeElement($category);
      }
  
      /**
       * Get categories
       *
       * @return \Doctrine\Common\Collections\Collection
       */
      public function getCategories()
      {
          return $this-&gt;categories;
      }
  
  
  }
  </code></pre>
  
  <p><strong>PostType</strong></p>
  
  <pre><code>class PostType extends AbstractType
  {
      /**
       * @param FormBuilderInterface $builder
       * @param array $options
       */
  
      public function buildForm(FormBuilderInterface $builder, array $options)
      {
          $builder
              -&gt;add('categories', 'entity', array(
                  'multiple' =&gt; false,   // Multiple selection allowed
                  'expanded' =&gt; false,   // Render as checkboxes
                  'class' =&gt; 'ShopManagementBundle:Category',
                  'property'     =&gt; 'name'
              ));
  
      }
      /**
       * @param OptionsResolver $resolver
       */
      public function configureOptions(OptionsResolver $resolver)
      {
          $resolver-&gt;setDefaults(array(
              'data_class' =&gt; 'Shop\Bundle\ManagementBundle\Entity\Post'
  
          ));
      }
      /**
       * @return string
       */
      public function getBlockPrefix()
      {
          return 'shop_bundle_managementbundle_posttype';
      }
  
  }
  </code></pre>