title: unable to transform value for property path "tagname". Expected a Doctrine\Common\Collections\Collection object
body: <p>I am working with two ManyToMany related entities, namely <code>category</code> and <code>tag</code>. </p>
  
  <p>The entity <code>Tag</code>(relevant details):</p>
  
  <pre><code>/**
   * 
   * @var string
   *
   * @ORM\Column(name="tagname", type="string")
   */
  protected $tagname;
  
  /**
   * @ORM\ManyToMany(targetEntity="Category", mappedBy="tags")
   */
  protected $categories; 
  </code></pre>
  
  <p>The entity Category(relevant details):</p>
  
  <pre><code>/**
   * 
   * @var string
   *
   * @ORM\Column(name="CategoryName", type="string",length=200)
   */
  protected $categoryname;
  
  /**
   * @ORM\ManyToMany(targetEntity="Tag", inversedBy="categories")
   */
  protected $tags;
  </code></pre>
  
  <p>I have a form with a select-input(CategoryType) and a multiple select-input(TagType) fields. Both the fields are EntityType fields. The TagType is embedded inside the CatgoryType. </p>
  
  <p>For this I am not able to utilise the <code>cascade=persist</code> functionality and am adding the submitted tags manually inside my controller. On submission the form data gets persisted in the database without any issues.</p>
  
  <p>The problem is, after submission, when I fetch the submitted category(and the associated tags) in my controller, and pass it to the form, I get this error - <code>Unable to transform value for property path "tagname": Expected a Doctrine\Common\Collections\Collection object.</code> </p>
  
  <p>The var_dump result of the fetched category object(<code>var_dump($category-&gt;getTags()-&gt;getValues());</code>) gives me an array of the associated Tag objects, with the property <code>protected 'tagname' =&gt; string 'tag1'</code>. </p>
  
  <p>From what I understand <code>Interface Collection</code> is quite similar to a php array and My guess is that the <code>tagname</code> field expects all the <code>tagname</code>s in an ArrayCollection or Collection object format. I am not sure whether what is the specific difference. </p>
  
  <p>However I am still clueless how do I pass the already persisted category object in my form.</p>
  
  <p>Here are the <code>categoryname</code>  and <code>tags</code> field in the <code>CategoryType</code>:</p>
  
  <pre><code>    $builder-&gt;add('categoryname', EntityType::class, array(
          'class' =&gt; 'AppBundle:Category',
          'query_builder' =&gt; function(EntityRepository $er) {
          return $er-&gt;createQueryBuilder('c')
              -&gt;orderBy('c.id', 'ASC');
  },
          'choice_label' =&gt; 'categoryname',
          'expanded' =&gt; false,
          'multiple' =&gt; false,
          'label' =&gt; 'Choose Category',
      ));
      $builder-&gt;add('tags', CollectionType::class, array(
          'entry_type' =&gt; TagType::class,
          'allow_add' =&gt; true,
          'by_reference' =&gt; false,
          'allow_delete' =&gt; true,
      )); 
  </code></pre>
  
  <p>Here is the embedded <code>tagname</code> field in the <code>TagType</code>:</p>
  
  <pre><code>    $builder-&gt;add('tagname', EntityType::class, array(
          'class' =&gt; 'AppBundle:Tag',
          'query_builder' =&gt; function(EntityRepository $er) {
      return $er-&gt;createQueryBuilder('t')
                      -&gt;orderBy('t.id', 'ASC');
  },
          'choice_label' =&gt; 'tagname',
          'expanded' =&gt; false,
          'multiple' =&gt; true,
          'label' =&gt; 'Choose Tags',
      ));
  </code></pre>
  
  <p>Any ideas?</p>