title: Symfony3 how to store user roles in database
body: <p>Symfony version: 3.1.3
  Database: MySQL</p>
  
  <p>I have the users table and it has a column as <strong>roles</strong>(LongText-DC2Type:array).</p>
  
  <p>In my controller I have created a dropdown box for the form as bellow,</p>
  
  <pre><code>$user = new Users;
  $form = $this-&gt;createFormBuilder($user)
          // some other fields
          -&gt;add('roles', ChoiceType::class, array(
                      'attr'  =&gt;  array(
                              'class' =&gt; 'form-control',
                              'style' =&gt; 'margin:5px 0;'),
                      'choices'  =&gt; array(
                              'Teacher'   =&gt; true,
                              'Student'   =&gt; true,
                              'Parent'    =&gt; true
                      ),
          ) )
          // some other fields
          -&gt;getForm();
  </code></pre>
  
  <p>and then I am getting the user selected role as bellow,(within the same controller)</p>
  
  <pre><code>if( $form-&gt;isSubmitted() &amp;&amp; $form-&gt;isValid() ){
      // some other codes
      $role   = $form['roles']-&gt;getData();
      // some other codes
  
      if( $role == 0 ){
          $userRole = array ('teacher');
      }
      elseif( $role == 1 ){
          $userRole = array ('student');
      }
      elseif( $role == 2 ){
          $userRole = array ('parent');
      }
  
      $user-&gt;addRole($userRole);
  
      $em = $this-&gt;getDoctrine()-&gt;getManager();
      $em-&gt;persist($user);
      $em-&gt;flush();
  }
  </code></pre>
  
  <p>But this gives me the following error,</p>
  
  <pre><code>Expected argument of type "array", "boolean" given 
  </code></pre>
  
  <p>I think I am doing it the wrong way and would like to know the right way to insert roles to the Database.</p>