title: symfony2 many-to-many form checkbox
body: <p>I have in symfony created 2 entities: User and Role in many-to-many relationship. That means every user can have more roles and roles can be set to many users.</p>
  
  <p><strong>User class:</strong></p>
  
  <pre><code>  /**
     * @ORM\Entity
     * @ORM\Table(name="JEP_User")
     * @ORM\Entity(repositoryClass="Chrchel\JepBundle\Repository\UserRepository")
     */
  class User implements AdvancedUserInterface {
  
  /**
   * @ORM\Id()
   * @ORM\Column(name="id",type="integer")
   * @ORM\GeneratedValue(strategy="AUTO")
   */
  private $id;
  
  /**
   * @ORM\Column(name="username",type="string",length=100,unique=true)
   */
  private $username;
  
   /**
   * @ORM\ManyToMany(targetEntity="Role", inversedBy="users")
   *
   */
  protected $roles;
  
  //....
  }
  </code></pre>
  
  <p><strong>Role class:</strong></p>
  
  <pre><code>/**
   * @ORM\Table(name="JEP_Role")
   * @ORM\Entity()
   */
   class Role implements RoleInterface {
  
  /**
   * @ORM\Column(name="id", type="integer")
   * @ORM\Id()
   * @ORM\GeneratedValue(strategy="AUTO")
   */
  protected $id;
  
    /** @ORM\Column(name="name", type="string", length=30) */
  protected $name;
  
   /** @ORM\Column(name="role", type="string", length=20, unique=true) */
  protected $role;
  
   /** @ORM\ManyToMany(targetEntity="User", mappedBy="roles") */
  protected $users;
   //...
   }
  </code></pre>
  
  <p>I cant figure how to compose query builder in Symfony2 to list all roles that exists and add it to the end of UserForm where can be selected (as checkboxes) roles granted to the user.
  I tried to use collection like this in UserType</p>
  
  <pre><code>-&gt;add('roles', 'collection',array('label' =&gt; 'Role', 'required' =&gt; false,'type'=&gt; new RoleType()))
  </code></pre>
  
  <p>The best I get from symfony are rows with textboxes with selected names of roles. But this is not, what I need.</p>