Couple thoughts:
* plain `joins` is going to do an INNER JOIN. You might want something like this:
includes(:comments, :likes).references(:comments, :likes).select('
cuusers.id').group('
cuusers.id').having(...)
* BUT: that query is going to be fairly inefficient, since it's going to have to compute *every* group before filtering them with HAVING.
Instead, you might want to do this bookkeeping differently by using the built-in counter caching mechanism. More info here:
Using counter caches in your example will mean adding a `comments_count` and `likes_count` column to your cuusers table. Then your scope could just use `where` to compare them...
--Matt Jones