title: Array to string conversion during POST only
body: <p>There are questions with the same title but they aren't related to POSTing.
  If I submit my form using Symfony I can submit with no problem.  Problem is when I submit my form using Angular using via POST method I created.  It gives me the exception "Notice: Array to string conversion".</p>
  
  <p>I know it has to do with my ManyToMany Relation (owners). If I don't add any owners it works fine. Problem is when I add owners.</p>
  
  <p>Here is my Stack Trace:</p>
  
  <pre><code>Stack Trace:
  
  1. in vendor/symfony/symfony/src/Symfony/Bridge/Doctrine/Form/ChoiceList/ORMQueryBuilderLoader.php at line 106 
  
  
  2. at ErrorHandler -&gt;handleError ('8', 'Array to string conversion', '/Applications/MAMP/htdocs/uploader/vendor/symfony/symfony/src/Symfony/Bridge/Doctrine/Form/ChoiceList/ORMQueryBuilderLoader.php', '106', array('v' =&gt; array('id' =&gt; '2', 'firstName' =&gt; 'Albert', 'lastName' =&gt; 'Jankowski', 'username' =&gt; 'ajankowski', 'password' =&gt; '$2y$13$7lXTaq3w45j3P0HEln71T.ItLxxf8ZX28UkNFpYFPULyR2a7pLW1C', 'email' =&gt; 'ajankowski@myemail.com', 'enabled' =&gt; true, 'salt' =&gt; null, 'usernameCanonical' =&gt; 'ajankowski', 'availableRoles' =&gt; array('ROLE_USER', 'ROLE_ADMIN'), 'emailCanonical' =&gt; 'ajankowski@myemail.com', 'plainPassword' =&gt; null, 'lastLogin' =&gt; null, 'confirmationToken' =&gt; null, 'roles' =&gt; array('ROLE_USER'), 'accountNonExpired' =&gt; true, 'accountNonLocked' =&gt; true, 'credentialsNonExpired' =&gt; true, 'credentialsExpired' =&gt; false, 'expired' =&gt; false, 'locked' =&gt; false, 'superAdmin' =&gt; false, 'user' =&gt; false, 'passwordRequestedAt' =&gt; null, 'groups' =&gt; array(), 'groupNames' =&gt; array()))) 
  in vendor/symfony/symfony/src/Symfony/Bridge/Doctrine/Form/ChoiceList/ORMQueryBuilderLoader.php at line 106
  
  
  3. at ORMQueryBuilderLoader -&gt;Symfony\Bridge\Doctrine\Form\ChoiceList\{closure} (array('id' =&gt; '2', 'firstName' =&gt; 'Albert', 'lastName' =&gt; 'Jankowski', 'username' =&gt; 'ajankowski', 'password' =&gt; '$2y$13$7lXTaq3w45j3P0HEln71T.ItLxxf8ZX28UkNFpYFPULyR2a7pLW1C', 'email' =&gt; 'ajankowski@myemail.com', 'enabled' =&gt; true, 'salt' =&gt; null, 'usernameCanonical' =&gt; 'ajankowski', 'availableRoles' =&gt; array('ROLE_USER', 'ROLE_ADMIN'), 'emailCanonical' =&gt; 'ajankowski@myemail.com', 'plainPassword' =&gt; null, 'lastLogin' =&gt; null, 'confirmationToken' =&gt; null, 'roles' =&gt; array('ROLE_USER'), 'accountNonExpired' =&gt; true, 'accountNonLocked' =&gt; true, 'credentialsNonExpired' =&gt; true, 'credentialsExpired' =&gt; false, 'expired' =&gt; false, 'locked' =&gt; false, 'superAdmin' =&gt; false, 'user' =&gt; false, 'passwordRequestedAt' =&gt; null, 'groups' =&gt; array(), 'groupNames' =&gt; array())) 
  
  4. at array_filter (array(array('id' =&gt; '2', 'firstName' =&gt; 'Albert', 'lastName' =&gt; 'Jankowski', 'username' =&gt; 'ajankowski', 'password' =&gt; '$2y$13$7lXTaq3w45j3P0HEln71T.ItLxxf8ZX28UkNFpYFPULyR2a7pLW1C', 'email' =&gt; 'ajankowski@myemail.com', 'enabled' =&gt; true, 'salt' =&gt; null, 'usernameCanonical' =&gt; 'ajankowski', 'availableRoles' =&gt; array('ROLE_USER', 'ROLE_ADMIN'), 'emailCanonical' =&gt; 'ajankowski@myemail.com', 'plainPassword' =&gt; null, 'lastLogin' =&gt; null, 'confirmationToken' =&gt; null, 'roles' =&gt; array('ROLE_USER'), 'accountNonExpired' =&gt; true, 'accountNonLocked' =&gt; true, 'credentialsNonExpired' =&gt; true, 'credentialsExpired' =&gt; false, 'expired' =&gt; false, 'locked' =&gt; false, 'superAdmin' =&gt; false, 'user' =&gt; false, 'passwordRequestedAt' =&gt; null, 'groups' =&gt; array(), 'groupNames' =&gt; array())), object(Closure)) 
  in vendor/symfony/symfony/src/Symfony/Bridge/Doctrine/Form/ChoiceList/ORMQueryBuilderLoader.php at line 107
  </code></pre>
  
  <p>My Entity:</p>
  
  <pre><code>/**
   * Company
   *
   * @ORM\Table()
   * @ORM\Entity(repositoryClass="AppBundle\Repository\CompanyRepository")
   */
  class Company
  {
    ......
    ......
  
    /**
     * @var User
     *
     * @ORM\ManyToMany(targetEntity="AppBundle\Entity\User")
     */
    private $owners;
  
    ......
    ......
  }
  </code></pre>
  
  <p>My Controller:</p>
  
  <pre><code>/**
   * @Route("", name="api_company_create")
   * @Method("POST")
   *
   * @param \Symfony\Component\HttpFoundation\Request $request
   *
   * @return Response $response
   */
  public function createAction(Request $request)
  {
    // Process the form.
    $company = new Company();
    $form = $this-&gt;createForm(new CompanyType(), $company);
    $this-&gt;processForm($request, $form, TRUE);
  
    if (!$form-&gt;isValid()) {
      $this-&gt;throwApiProblemValidationException($form);
    }
  
    $em = $this-&gt;getDoctrine()-&gt;getManager();
    $em-&gt;persist($company);
    $em-&gt;flush();
  
    $response = $this-&gt;createApiResponse($company, 201);
  
    $companyUrl = $this-&gt;generateUrl(
      'api_company_show',
      ['id' =&gt; $company-&gt;getId()] );
  
    $response-&gt;headers-&gt;set('Location', $companyUrl);
  
    return $response;
  }
  
  /**
   * Process the form.
   *
   * @param \Symfony\Component\HttpFoundation\Request $request
   * @param \Symfony\Component\Form\FormInterface $form
   * @param boolean $removeExtraFields
   * @param Company $currentCompany
   */
  private function processForm(Request $request, FormInterface $form, $removeExtraFields = FALSE, $currentCompany = NULL)
  {
    $data = json_decode($request-&gt;getContent(), true);
  
    $clearMissing = $request-&gt;getMethod() != 'PATCH';
    $form-&gt;submit($data, $clearMissing);
  }
  
  
  
  /**
   * Company
   *
   * @ORM\Table()
   * @ORM\Entity(repositoryClass="AppBundle\Repository\CompanyRepository")
   */
  class Company
  {
    ......
    ......
  
    /**
     * @var User
     *
     * @ORM\ManyToMany(targetEntity="AppBundle\Entity\User")
     */
    private $owners;
  
    ......
    ......
  }
  </code></pre>
  
  <p>I tried adding __String() to my Company Entity but that didn't help.</p>
  
  <pre><code>  /**
     * Transform to string
     *
     * @return string
     */
    public function __toString()
    {
      return (string) $this-&gt;getOwners();
    }
  </code></pre>