Get the user's perms of the categories and forums with jointure
<p>I use Symfony 3 and I am making my own forum and I am currently at the permissions.</p>

<p><a href="http://i.stack.imgur.com/uifwM.png" rel="nofollow">My table</a></p>

<p>As you can see, my user can have many group, so I would like to get with my query, the list of my categorie (with its perms) and their forum (with perms of each of them). I want to get the best of all of his perms, in my screen, the (user_group == 2) have no perm, and the (user_group == 1) have all of the perm. I want get all of the user line and group by them and using MAX on each autorization (can_*) to know what he can do.</p>

<p>(I don't want the get the better group perms of the user, but rather the best of each fields)</p>

<p><a href="http://i.stack.imgur.com/nEBW3.png" rel="nofollow">Other example with my category_id == 1</a></p>

<p>I would get all of true result</p>

<p>My current query is like:</p>

<pre><code>public function getCategoriesWithForums(\UserBundle\Entity\User $user)
{
    $ids = array();
    foreach ($user-&gt;getGroups() as $group) 
    {
        $ids[] = $group-&gt;getId();
    }

    return $this-&gt;createQueryBuilder('c')
        // permissions catégory
        -&gt;innerJoin('c.permissions', 'cp')-&gt;addSelect('cp, MAX(cp.canSee), MAX(cp.canEnter), MAX(cp.canPost), MAX(cp.canReply), MAX(cp.canEdit), MAX(cp.canDelete)')
            -&gt;andWhere('cp.userGroup IN (:ids)')-&gt;setParameter('ids', implode(',', $ids))

        -&gt;innerJoin('c.forums', 'f')-&gt;addSelect('f')
        // permissions forums
        -&gt;innerJoin('f.permissions', 'fp')-&gt;addSelect('fp, MAX(fp.canSee), MAX(fp.canEnter), MAX(fp.canPost), MAX(fp.canReply), MAX(fp.canEdit), MAX(fp.canDelete)')
            -&gt;andWhere('fp.userGroup IN (:ids)')-&gt;setParameter('ids', implode(',', $ids))

        -&gt;leftJoin('f.lastPost', 'lastPost')-&gt;addSelect('lastPost')
        -&gt;leftJoin('lastPost.topic', 'topicLastPost')-&gt;addSelect('topicLastPost')

        -&gt;orderBy('c.position', 'ASC')
        -&gt;addOrderBy('f.position', 'ASC')
        -&gt;getQuery()-&gt;getResult();
}
</code></pre>

<p>Query generated by Symfony 3: (need 10 reputations): pastebin dot com/0vX9ej2a</p>

<p>And, last thing, I got this <strong>error</strong>.. </p>

<blockquote>
  <p>SQLSTATE[42000]: Syntax error or access violation: 1140 In aggregated
  query without GROUP BY</p>
</blockquote>

<p>expression #13 of</p>

<pre><code> SELECT list contains nonaggregated column 'gtav.f2_.id'; this is incompatible with sql_mode=only_full_group_by
</code></pre>

<p>Do you have any idea to fix that and to get the correct result?
I hope you will can help me about that</p>