title: Symfony2 doctrine: How to select users that are not in groups with doctrine query builder
body: <p>I have symfony2 and fos user bundle installed and I'm trying to reproduce this MySql query in Symfony2 doctrine query builder.</p>
  
  <p>This query should select users not belonging to listed groups.</p>
  
  <pre><code>SELECT *  FROM 
      fos_user_user 
  left join 
      fos_user_user_group  on fos_user_user.id = fos_user_user_group.user_id   
      and fos_user_user_group.group_id in (1,2,3,4,5,6,7,8)
  where 
      fos_user_user_group.user_id is null
  </code></pre>
  
  <p>Doctrine manual gives example that checks for user belonging to single group, but no reference when groupId <strong>is array of several group ID's</strong>. :groupId is not integer, doctrine gives an error.</p>
  
  <pre><code>$query = $em-&gt;createQuery('SELECT u.id FROM CmsUser u WHERE :groupId MEMBER OF u.groups');
  $query-&gt;setParameter('groupId', $group);
  $ids = $query-&gt;getResult();
  </code></pre>
  
  <p>Taken from <a href="http://doctrine-orm.readthedocs.org/en/latest/reference/dql-doctrine-query-language.html" rel="nofollow">14. Doctrine Query Language</a></p>
  
  <p>Mysql scheme is default FOS User bundle. In simplified manner it looks like this:</p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS `fos_user_user` (
    `id` int(11) NOT NULL,
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
  
  CREATE TABLE IF NOT EXISTS `fos_user_group` (
    `id` int(11) NOT NULL,
    `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
    `roles` longtext COLLATE utf8_unicode_ci NOT NULL COMMENT '(DC2Type:array)',
    `deletedAt` datetime DEFAULT NULL
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
  
  CREATE TABLE IF NOT EXISTS `fos_user_user_group` (
    `user_id` int(11) NOT NULL,
    `group_id` int(11) NOT NULL
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
  </code></pre>